如何添加一个正则表达式,以在HTML中检查 元素的值?
使用 pattern属性设置正则表达式,以检查<input>元素的值。您可以尝试运行以下代码来实现 模式 属性-
示例
<!DOCTYPE html> <html> <head> <title>HTML novalidate attribute</title> </head> <body> <form action = "" method = "get" novalidate> Student Name<br><input type = "name" name = "sname"><br> Rank<br><input type = "number" name = "rank"><br> Student Country <br><input type = "text" name = "ccode" pattern="[A-Za-z]{3}" title = "country code"><br> <input type = "submit" value = "Submit"> </form> </body> </html>