dimanche 19 avril 2015

Various Regex Validation

I'm new to regex. I have an array (call it arr1) with assorted values. I am trying to validate that it has the following format for its elements with arr1[x] provided as an example



arr1[x] = "item1, item2, item3, item4, item5":

item 1 - "abcdef" (variable number of letters) or "abcdef asdf" (variable number of letters separated by one whitespace character)
item 2 - "abcdef" (variable number of letters) or "abcdef asdf" (variable number of letters separated by one whitespace character)
item 3 - "12345678" (eight digits)
item 4 - "123 456 7890" (telephone number with 3 digits followed by 3 digits followed by 4 digits with two whitespace characters as shown)


Here is a snippet of what I have for phone number validation (not sure how the second line works - got it from a different SO thread):



function f(s) {
var s2 = (""+s).replace(/\D/g, '');
var m = s2.match(/^(\d{3})(\d{3})(\d{4})$/);
}


Thanks in advance for any assistance.


Aucun commentaire:

Enregistrer un commentaire