Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法以两种形式验证电话号码?我想验证以“+”开头的数字和不带“+”的电话。例如,它应该传递数字 +238472636 和 193785626。
Pattern: /^[\+]\d+$/
使用?对于可选字符或块:
Pattern: /^[\+]?\d+$/
这 ?量词匹配前面的元素零次或一次。它等价于 {0,1}。? 是一个贪心量词,其惰性等价物是 ??
所以你的注册。ex会是这样的。。
/^[\+]?\[0-9]+$/ OR /^[\+]?\d+$/