繁体   English   中英

在Javascript中使用正则表达式验证输入

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM