[英]how to implement validation for phone number?
I've created a form and need to validate field by it's content (empty, .empty) and phone number field so phone number match regex (ukrainian phone number).我创建了一个表单,需要通过它的内容(空,.empty)和电话号码字段来验证字段,以便电话号码匹配正则表达式(乌克兰电话号码)。 this option does not work (
此选项不起作用(
const regex = /^\+[0-9]{3}\s\((\d+)\)-\d{3}-\d{2}-\d{2}/g
const validate = (username, phone, comment) => {
if ((username.length === 0 || phone.length === 0, comment.length === 0)) {
setErrorEmpty('the field is empty !')
} else if (!phone.match.regex) {
setPhoneErr('the format is wrong !')
} else {
setValidated(true)
}
}
ukrainian number consists of 10 digits: ex: 0954343333
or (38)0954343333
乌克兰号码由 10 位数字组成:例如:
0954343333
或(38)0954343333
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.