Question
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
LTIMindtree
IN
Last activity: 21 Dec 2022 0:32 EST
Need an Edit Validate rule xxx-xxxxx in the format
Hi,
We have a requirement like there is a filed which is allowed only integers and the first digit should starts with "4" ,there should be a "-" after three digits and it should be in the format like 4xx-xxxxx(eg:432-87613).I was created an edit validate rule with custom java code but it was not working. So, please suggest any solution or in any possible way to achieve this.
// Regex to check valid Customer ID String regex= "^[4]{1}[0-9]{2}-?[0-9]{5}$";
// Compile the ReGex java.util.regex.Pattern p = java.util.regex.Pattern.compile(regex);
// If the string is empty, return false if (theValue == null || theValue.trim().equals("")) return false;
// Pattern class contains matcher() method to match the given string and the regular expression java.util.regex.Matcher m = p.matcher(theValue);
// Return if the string matched the ReGex return m.matches();