javascript - Regex for Arrays within an Array -


i have array of arrays (call outer array arr1) numerous values inner arrays. trying validate inner arrays have following format elements arr1[1] provided example (the other elements of arr1, i.e. arr1[2], arr1[3], arr1[4], etc. of same format

arr1[1] = ['item1', 'item2', 'item3', 'item4', 'item5']:  item 1 - "abcdef" (variable number of letters) item 2 - "abcdef" (variable number of letters) item 3 - "abcdef" (variable number of letters) or "abcdef asdf" (variable number of letters separated 1 whitespace character)     item 4 - "12345678" (eight digits) item 5 - "123 456 7890" (telephone number 3 digits followed 3 digits followed 4 digits 2 whitespace characters shown) 

here snippet of have far (not sure how second line works - got different thread):

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

thanks in advance assistance.

you can use following:

item 1 - \w+ (variable number of letters) item 2 - \w+ (variable number of letters) item 3 - \w+(?:\s\w+)? (variable number of letters) or                           (variable number of letters                            separated 1 whitespace character)     item 4 - \d{8} (eight digits) item 5 - (?:\d{3}\s){2}\d{4} (telephone number 3 digits                                followed 3 digits followed 4                                digits 2 whitespace characters shown) 

edit: can use ^\w+?,\s\w+?,\s\w+(?:\s\w+)?,\s\d{8},\s(?:\d{3}\s){2}\d{4}$ directly validate string.

ex:

function validatestr(str) {   return (/^\[\s'\w+?',\s'\w+?',\s'\w+(?:\s\w+)?',\s'\d{8}',\s'(?:\d{3}\s){2}\d{4}'\s\]$/).test(str); } 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -