[英]Validating input using regular expression in Javascript
我需要验证文本框,它应该只接受字母(大写或小写),数字和.,?-_
。 它不应该接受任何其他值。 它不应该接受相同的值,如......
或,,,,,
或-----
或????
或_____
。 它不应该接受像这样的值,._
它应该包含字母或数字,例如_.ab.?
。
所以你希望字符串包含至少一个(ASCII)字母数字字符和至少两个不同的字符?
尝试
/^(?=.*[A-Z0-9])(?!(.)\1*$)[A-Z0-9.,?_-]*$/i
说明:
^ # start of string
(?=.*[A-Z0-9]) # assert that there is at least one of A-Z or 0-9
(?!(.)\1*$) # assert that the string doesn't consist of identical characters
[A-Z0-9.,?_-]* # match only allowed characters
$ # until the end of the string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.