I have one requirement wherein I have to put a validation check on fax number using Regex.The accepted characters in fax number are + . and numbers from 0 to 9. For this I have written the following javascript function
function validateFax(checkField) {
if (checkField.value.length > 0) {
var faxRegEx = /[\+? *[1-9]+]?[0-9 ]+/;
if (!checkField.value.match(faxRegEx)) {
return false;
}
}
return true;
}
but it is not helping me to check all acceptable characters. Moreover it checks only 3 to 4 characters, but my fax number can consist of any number of characters. I am new to Regex. Can any one kindly tell me how can I modify this function to make it aligned to my requirement. Thanks in advance.
/^\+?[0-9]+$/
The above regex would allow a +
sign at the beginning of the number. Then 0-9 can appear any number of times (more than equals to one). So this regex would allow: +123456789
123456789
etc.
If you want to limit the minimum number of digits, you can modify the regex in the following way:
/^\+?[0-9]{6,}$/
here {6,}
represents that [0-9] must appear at least 6 times.
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