Difference between revisions of "Validating Postal Codes"
From SmartWiki
Lorena Ruiz (talk | contribs) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | You can use [[JavaScript Validation]] to ensure the postal code [[standard field]] on contact [[profile]]s conforms to a certain pattern. For example, Canadian postal codes follow the pattern of ''LNL NLN'' | + | You can use [[JavaScript Validation]] to ensure the postal code [[standard field]] on contact [[profile]]s conforms to a certain pattern. For example, Canadian postal codes follow the pattern of ''LNL NLN''<br /> |
− | Where | + | Where <br /> |
− | L = a letter | + | L = a letter<br /> |
N = a number | N = a number | ||
Line 16: | Line 16: | ||
:Now, when a postal code is entered, if the Postal Code is not in the specified format, the user will be prompted with the ''Validation Message''. | :Now, when a postal code is entered, if the Postal Code is not in the specified format, the user will be prompted with the ''Validation Message''. | ||
+ | |||
+ | ==To Only Enforce Postal Code Formats for a Particular Country== | ||
+ | To only enforce the above formats for users who live in Canada, enter the following into the ''Validation'' setting: | ||
+ | |||
+ | document.frmuser.ucountry.value!="10" || isMatch(@value@, 'LNL NLN', true) | ||
+ | |||
+ | ==Zip Code Format== | ||
+ | To enforce a US zip code of 5 or 5+4 digits, enter the following into the ''Validation'' setting: | ||
+ | |||
+ | isFloat(@value@.replace(/-/g,""),true) && (isMatch(@value@, 'NNNNN', false) || isMatch(@value@, 'NNNNN-NNNN', false)) | ||
+ | |||
+ | Sample validation message: | ||
+ | |||
+ | Zip Code must be in the format of '#####' or '#####-####', example: '32334' or '32334-0092'. | ||
==See Also== | ==See Also== | ||
* [[Contact_and_Account_Standard_Fields#Validation|Validating Contact Standard Fields]] | * [[Contact_and_Account_Standard_Fields#Validation|Validating Contact Standard Fields]] | ||
* [[JavaScript Validation]] | * [[JavaScript Validation]] | ||
+ | * [[Country Codes]] - for the ''value'' to be used to reference other countries | ||
[[Category:Validation]] | [[Category:Validation]] |
Latest revision as of 15:53, 3 December 2015
You can use JavaScript Validation to ensure the postal code standard field on contact profiles conforms to a certain pattern. For example, Canadian postal codes follow the pattern of LNL NLN
Where
L = a letter
N = a number
Example: M5V 2H1
Contents
Steps
- Click on Global Settings
- Under User & Contact Settings, click on the hyperlink for User/Contact Standard Field Settings
- From the left-hand list of standard fields, click on the hyperlink for Zip / Postal Code
- In the Validation setting, enter isMatch(@value@, 'LNL NLN', true)
- Enter a Validation Message, such as "Postal Code must be in the format of 'A#A #A#', example: 'M5V 2H1'."
- Now, when a postal code is entered, if the Postal Code is not in the specified format, the user will be prompted with the Validation Message.
To Only Enforce Postal Code Formats for a Particular Country
To only enforce the above formats for users who live in Canada, enter the following into the Validation setting:
document.frmuser.ucountry.value!="10" || isMatch(@value@, 'LNL NLN', true)
Zip Code Format
To enforce a US zip code of 5 or 5+4 digits, enter the following into the Validation setting:
isFloat(@value@.replace(/-/g,""),true) && (isMatch(@value@, 'NNNNN', false) || isMatch(@value@, 'NNNNN-NNNN', false))
Sample validation message:
Zip Code must be in the format of '#####' or '#####-####', example: '32334' or '32334-0092'.
See Also
- Validating Contact Standard Fields
- JavaScript Validation
- Country Codes - for the value to be used to reference other countries