I'm evaluating a phone number in js with this regex:
/[a-z]/i.test(this.state.phone)
Now I need to limit its length to 30 chars. I tried so many times but basically I know I need to specify max lenght in curly braces like this:
/[a-z]{30}/i.test(this.state.phone)
But this way the check about letters doesn't work anymore. I've spended too much time on it I need some help!
EDIT: to clarify I need to avoid any letter (upper or lowercase) or special char but round brackets, space, dot, minus and plus sign. So this is ok:
+001.333 123456
this not
+001 333 123456v
Now I need to limit its length to 30 chars
/[az]{30}/i
will check for exact 30 characters, you need to specify minimum length as well.
/\d{1,30}/i
{1,30}
will check for min 1
and max 30
characters.
Also, if there no other characters allowed in this.state.phone
, then asset start of string ^
and end of string $
as well.
/^(\+)?[0-9\s]{1,30}$/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.