javascript - Java Script Regular expression for number format not working -
javascript - Java Script Regular expression for number format not working -
i want input user 888-999-6666..i.e. 3 numbers '-' 3 numbers 1 time again '-' , 4 numbers. using next regular look in javascript.
var num1=/^[0-9]{3}+-[0-9]{3}+-[0-9]{3}$/; if(!(form.num.value.match(num1))) { alert("number cannot left empty"); homecoming false; }
but not working. if utilize var num1=/^[0-9]+-[0-9]+-[0-9]$/;
wants @ to the lowest degree 2 '-' no restriction on numbers.
how can re requirement? , why above code not working?
remove +
symbol nowadays after repetition quantifier {}
. , replace [0-9]{3}
@ lastly [0-9]{4}
, allow 4 digits after lastly -
symbol.
var num1=/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
demo
you write [0-9]
\d
.
javascript regex
Comments
Post a Comment