javascript - Regular expression not supporting line skipping \n -
i'm trying find right regular expression number line skip @ end ( \n
) every time it's not working.
my regular expression /^\d+(\n)$/
.
edit : text area contains :
22\n 33
here's code ( i'm trying validate what's in textarea , it's numbers going there \n
@ end of each lines ) :
function validechamp() { var rexp1 = /^\d+(\n)$/; var achamps = document.queryselector("textarea").value; if (rexp1.test(achamps.value)==true){ alert("valide") } else { alert("invalide") return false; } }
if want check line containing number on it, can use:
/(^|\n)\d+(\r?\n)/
if want check there's number, , newline, , nothing else:
/^\d+(\r?\n)$/
(which checking for, that's odd input pattern.)
if want make sure textarea has lines numbers, might simpler check string.replace(/[0-9\r\n]/g, '') == ''
. confirm if contains numbers , newlines.
Comments
Post a Comment