javascript - Regular expresssion to validate zipcode/postal code -
i want validate zipcode or pincode in address fields. that's why trying write regular express except a-z (upper , lower both), 0-9 numbers, round breckets (eg. '()' ) , hyphen (-) , space. rules must followed single white space can not on first position, 2 or more white space can not allowed.
some of invalid entries
1254588 125 255 ((125)) 255 125--255 (125) (255) 125>2458 el$ 2458 @l$ 2458
if rules matter, it's easy:
^ # start of string (?! ) # first character mustn't space (?!.* ) # no 2 spaces in row [a-za-z0-9 ()-]* # match number of these allowed characters $ # end of string
or, javascript:
/^(?! )(?!.* )[a-za-z0-9 ()-]*$/
but i'm guessing strings "))))(((("
, "-------"
, "a"
or ""
shouldn't matched, allowed rules.
Comments
Post a Comment