i need to validate this type of string
0415256987, 0452 654 987, 0411 236589, 0 410 258 987 etc.
each number has 10 digits and spaces commas, new line, are allowed.
in my project this is a textarea where users enter comma delimited string of mobile numbers. the regex is for the js validation. the spaces and new lines are allowed to give users less frustrating experience of entering the numbers and to accommodate various styles of entering the mobile number
how would you write a regular expression to validate it?
i tried various regex strings and all of them stop working after first comma. i better post my js. perhaps there is some other bug why it does not work. im using jquery validate plugin. i also removed 10digit check as well as it interferes with the validation error msgs and it can be easily fixed (rejected or parsed) on the server.
$.validator.addMethod("numbersCommasSpacesOnly",
function(value, element){
return /^(\d\s*\r*\n*-*,*)$/.test(value);
},
"Only numbers, spaces and commas are allowed"
);
$("#UserContactsOptinForm").validate({
rules: {
"data[User][contacts]": {// compound rule
required: true,
numbersCommasSpacesOnly: true
}
},
messages: {
"data[User][contacts]": {
required: "this field is required"
}
}
});
});
thank you