Validate zip and display error with onBlur event
- by phil
Check if zip is 5 digit number, if not then display 'zip is invalid'. I want to use onBlur event to trigger the display. But it's not working.
<script>
$(function(){
function valid_zip()
{
var pat=/^[0-9]{5}$/;
if ( !pat.test( $('#zip').val() ) )
{$('#zip').after('<p>zip is invalid</p>');}
}
})
</script>
zip (US only) <input type="text" name='zip' id='zip' maxlength="5" onBlur="valid_zip()">