Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 92756

Re: Validating two different zip code formats

$
0
0

Another variation:

 

/*
A breakdown of the ZIP code regular expression follows:
/^ # Assert position at the beginning of the string.
[0-9]{5} # Match a digit, exactly five times.
(?: # Group but don't capture...
- # Match a literal "-".
[0-9]{4} # Match a digit, exactly four times.
) # End the noncapturing group.
? # Repeat the preceding group between zero and one time.
$/ # Assert position at the end of the string.
*/


var RegExp_USZipCode_Valid = /^[0-9]{5}(?:-[0-9]{4})?$/; // US ZipCode 5 and 5+4 formats;
if(RegExp_USZipCode_Valid.test(event.value) == false) {
app.alert("Not a valid format for US Zip Code or US Zip Code + 4", 1, 0);
}

 

It is also possible to write a keystroke validation.


Viewing all articles
Browse latest Browse all 92756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>