I have a text area and a user can input US zip codes in it separated by a comma or (comma and space).
It could be like 12345,45678, 89654
The following regex is working and is removing not allowed characters:
$object.val($object.val().replace(/[^\d\, ]/g, ''));
I would like to enhance it, so that
- i always should have 5 digits in the beginning
- after 5 digits, there should be a comma or comma and space
- comma or (comma and space) should not be at the very end of the string. It must be 5 digit number at the end.
This needs to tackle the copy paste as well. The user may copy paste invalid length for the zip code.
Thanks