Pages
Friday, November 18, 2016
Salesforce: Regex allow only Numbers and Special Character
Phone field in Salesforce by default will accept any characters with maximum of 40 characters. Because of this flexibility, user can enter any data and cause the data become dirty.
Requirement: to allow only numbers, space, and special characters + ( ) . - / in phone, fax, mobile field.
Solution: use Regex in Validation Rules
NOT ISBLANK( Phone ) &&
NOT(REGEX( Phone, "^(?=.*?[1-9])[0-9()/\\-\\+\\s\\.]+$"))
Regular expression syntax is based on Java Platform SE 6 syntax. However, backslash characters (\) must be changed to double backslashes (\\) because backslash is an escape character in Salesforce.
Reference:
Labels:
Validation Rule
Subscribe to:
Post Comments (Atom)
This does allow alphabetic characters, so, your REGEX formula is not working as described in your blog.
ReplyDeletecan you share text you test?
Delete