javascript - it is possible to find out on which line of the input field is not a match per regex? -
here regex
/([0-9]{2}\/[0-9]{2})/gm
and when in input field this
09/09 03/65 0938 05/37
i want alert this: there error in third line
it possible somehow?
split value new line , check each line against regex pattern.
for example:
var regex = /^[0-9]{2}\/[0-9]{2}$/; var lines = val.split(/\r?\n/); for(var = 0; i<lines.length ; i++){ if (lines[i].match(regex) == null) { alert('there error in ' + (i + 1) + ' line'); break; } }
note: use ^
(beginning of line) , $
(end of line) match whole line.
Comments
Post a Comment