Randy Geily
Randy Geily

Reputation: 139

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.

Upvotes: 0

Views: 27

Answers (2)

Kyo
Kyo

Reputation: 964

See the line below:

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

Upvotes: 1

Kamehameha
Kamehameha

Reputation: 5488

This should work -

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

and test it using test() like this -

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

Upvotes: 1

Related Questions