Another week, another validation function. Last week was a little long, so this week we'll do a bit shorter one: validating a United States ZIP code. The pattern is simple enough that I don't think an explanation is warranted.
ASP
function isValidZIPCode(zipCode)
dim regEx
set regEx = new RegExp
with regEx
.IgnoreCase = True
.Global = True
.Pattern = "^[0-9]{5}(-[0-9]{4})?$"
end with
if regEx.Test(trim(CStr(zipCode))) then
isValidZipCode = True
else
isValidZipCode = False
end if
set regEx = nothing
end function
PHP
function isValidZIPCode($zipCode)
{
return (preg_match("/^[0-9]{5}(-[0-9]{4})?$/i", trim($zipCode)) > 0) ? true : false;
}
No comments:
Post a Comment