[英]I want to validate the phone number in javascript
I want to validate a phone number it should contain minimum of 7 digits.我想验证一个至少应包含 7 位数字的电话号码。
const inputText = form.phone.value.trim();
const pattern = /^\d{7}$/;
if (!inputText.match(pattern)) {
alert('Phone must be minimum of 7 digits.', 'error');
return;
}
The above code is what i tried.上面的代码是我试过的。 But it returns error if it exceeds more than 7 digits.
但是如果超过 7 位就会返回错误。 it validates exactly 7 digits.
它验证了 7 位数字。 And could anyone explains how these patterns are written.
任何人都可以解释这些模式是如何编写的。
[\d]{7,}
This should do it.这应该这样做。 The {7,} means you need at least 7 characters.
{7,} 表示您至少需要 7 个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.