Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript phone number validation

I want to make sure phone numbers are entered correctly. They are UK numbers and cannot contain any symbols or letters. They must be 11 in length.

So I have tried the following:

else if (phone == null || !phone.toString().match(/^[-]?\d*\.?\d*$/)){

But this actually allows any length and even blank input.

What should I do to validate phone numbers? I'm not that experienced with Javascript.

like image 382
ryryan Avatar asked Dec 08 '25 01:12

ryryan


1 Answers

The regexp to match exactly 11 digits is /^\d{11}$/.

like image 111
ChrisJ Avatar answered Dec 10 '25 13:12

ChrisJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!