简体   繁体   中英

javascript regex (regular expression)

I need to validate phone numbers. it must have a "+" sign followed by [0-9].

I need something like /^ + . [0-9]*$/

I don't know how to implement the "+" sign and how to have it validate only once. Concerning the length It does not matter for my purpose.

This should work -

/^\+[0-9]+$/

and test it using test() like this -

> /^\+[0-9]+$/.test("+9009900")
true

见下面的行:

str.match(/^\+[0-9]+$/)

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