+ Start a Discussion
vicky30vicky30 

validaition to allow only numbers & Hyphen(-)

Hi Firiends,
The below validation rule is not working, please help me on this

NOT($Profile.Name ='System Administrator'),ISPICKVAL(country, 'Brazil'),
OR(
NOT(
ISNUMBER( Zipcode__c)), LEN(Zipcode__c)<8,REGEX( Zipcode__c, "^(?!.*/)[a-zA-Z'*,/\r\n]+$")
)
)

The Zipcode should allow only numbers & one special character Hyphen(-)
Please anyone help me on this issue.
 
Deepali KulshresthaDeepali Kulshrestha
Hi vicky30,

Greetings to you!
Please try the below:-

AND(
NOT(ISBLANK(Phone)),
NOT(REGEX(Phone, "[0-9()-]+"))
)

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
SarvaniSarvani
Hello Vicky30,

Please use REGEX(Zipcode__c, "[0-9-]+") in your formula to accept only numbers and character "hypen". Modify your other functions like LEN and ISNUMBER accordingly.

Hope this helps !

Thanks,
Sarvani
 
vicky30vicky30
Hi Sarvani & Deepali,

I tried both Regex, But its not working.

AND(NOT($Profile.Name ='System Administrator'),ISPICKVAL(Country__c, 'Brazil'), 
OR( 
NOT( 
ISBLANK( Zipcode__c)), LEN(Zipcode__c)<8,NOT(REGEX( Zipcode__c, "[0-9-]+")) 


 
SarvaniSarvani
Hey Vicky30,

You need to modify your formula as per your requirement. Having NOT(REGEX(Zipcode__c,"[0-9-]+"))  alone in your fomula field as shown in below scrrenshot will only allow numbers in combination with hyphens. As you have other functions, please make sure they are working.

 User-added image

Hope this helps !

Thanks,
Sarvani