简体   繁体   中英

Regular expression validation for telephone number

I am using the following regex for telephone number validation. It is allowing all the cases except one.
^(\\+?\\ *[0-9]+)([0-9 ]*)([0-9 ])*$|(^ *$)

The conditions are
1. Allow numeric values
2. Allow plus sign only in the beginning

The regex is getting failed while I enter the first character as plus sign. If I have entered a number after the plus sign it will work. My requirement is the form should valid while entering the plus sign as the first character. I am using a Angular reactive form. So error will fire entreating the first character itself.

Thanks in advance.

Try this ^(\\+?)([0-9 ]*)([0-9 ])*$|(^ *$) .

But what you had initially is also fine but as you said its not your requirement, try the above one

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.

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