I'm very new to javascript, I just want a reqular expression for validating phone numbers for one of my text field.
I can accept -+ () 0-9
from users, do you have regex for this one or a regex for phone numbers better then the one i need?
Thanks in advance.
/^([+]\d{2})? \d{10}$/ This is how this regex for mobile number is working. + sign is used for world wide matching of number.
Validate a Phone Number Using a JavaScript Regex and HTML function validatePhoneNumber(input_str) { var re = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/; return re. test(input_str); } function validateForm(event) { var phone = document. getElementById('myform_phone').
It's used to match strings or parts of strings and for search and replace operations. jQuery uses regular expressions extensively for such diverse applications as parsing selector expressions, determining the type of browser in use, and trimming whitespace from text.
Use this rexeg
/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/
supported
Try this
function validatePhone(phoneNumber){
var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
return phoneNumberPattern.test(phoneNumber);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With