Indian pincode validation regex - Only six digits, shouldn't start with `0`
The problem with ^[1-9][0-9]{6}*$
is it is an invalid regex because of {6}*
and ^([^0][0-9]){6}$
is that it is allowing any character that is not 0
followed by six digits.
Use
^[1-9][0-9]{5}$
Explanation:
^
: Starts with anchor[1-9]
: Matches exactly one digit from 1 to 9[0-9]{5}
: Matches exactly five digits in the inclusive range0-9
$
: Ends with anchor
Regex101 Playground
HTML5 Demo:
input:invalid {
color: red;
}
<input type="text" pattern="[1-9][0-9]{5}" />