function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Animesh DattaAnimesh Datta 

Phone number Vallidation Regex, Pattern, matcher

Hi,
I am putting one validation for 3 phone number fields in community. User can not add characters except ( )  - space and number.
Pleasse help on this. here is the sample code.
Pattern p = Pattern.compile('(REGEX(Phone, "^(?=.*?[1-9])[0-9()-]+$"))');
Matcher otherphone;
Boolean isPhoneError = false;
	if (newUserContact.otherphone != null && newUserContact.otherphone != ''){
		otherphone = p.matcher( (string)newUserContact.otherphone);
		if(otherphone.matches()){
			isPhoneError = true;
		}
	}			
		if(isPhoneError)
			{
				ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, system.label.PhoneInvalid);
				ApexPages.addMessage(msg);
				return false;
			}

 
sandeep sankhlasandeep sankhla
Hi

Please refere below link for more details
http://regexlib.com/(X(1)A(nDLmjU9Uol4BI8_ub94cgATOKekjnlf7bPpYZj6bJTMEnPllSXN0NZrDs20vanqoaSwyiCgfZxuEpevjZjyUY6gCJMC0T4XzvUYuj1o3J45JzCw7u58o5r_pr8T884YbhmTlstnT0UXkNvBm69KJAYECMU03jXhd9QC3ewX27DggD4D8s7zacfshSC22HDhs0))/Search.aspx?k=phone&c=-1&m=-1&ps=20

Thanks,
Sandeep