javascript validate zip regular expression

Posted by phil on Stack Overflow See other posts from Stack Overflow or by phil
Published on 2010-06-11T05:31:27Z Indexed on 2010/06/11 5:42 UTC
Read the original article Hit count: 189

Filed under:
|

It's not working. Probably it's syntax error, but I can't figure it out.

<script src="jquery-1.4.2.min.js" type="text/javascript"></script>

<script>
pattern=/^[0-9]{5}$/;
if (!pattern.test($('#zip').val))
{$('#zip').append($('<p>',{html: zip is invalid}));}
</script>

zip (US only): <input type="text" name='zip' id='zip' maxlength="5">

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery