BhavaniB1841
(Bhavani Basireddygari)
February 22, 2023, 8:10am
1
Hi ,
I have requirement to implement a validation logic for Text field.
The field should accept the mentioned format, alphabets with space or hypen, or alphabets with hypen, or alphabets with space
otherwise error should be thrown.
examples: ABC_XYZ PQR
PQRTY RTYE_ABC
3)TYUIO
4)ABC XYZ
5)XYZTY_POI
Could you help with java code required to implement this in edit validate rule.
Bhumireddy
(Bhumireddy Veera Ashokkumarreddy)
February 22, 2023, 9:12am
2
Hi @BhavaniB1841
Please refer my previous post, you will get some idea.
I hope this will help you.
Thanks,
Ashok
@BhavaniB1841
Please write this code in edit validate, and confugure this on the property rule Advanced.
String regex= “+$”;
java.uitl.regex.Pattern p=java.util.regex.Pattern.compile(regex);
if(theValue== null || theValue.trim().equals(“”) return false;
java.util.regex.Matcher=p.matcher(theValue);
if(m.matches())
return m.matches();
else
theProperty.addMessage(" write your error message");
BhavaniB1841
(Bhavani Basireddygari)
February 24, 2023, 6:02am
4
Hi @Satish Sudagoni ,
if(theValue== null || theValue.trim().equals(“”) return false;
in the above line “)” is missing for if condition, i have included “)” ( see the attachments) it but still i am getting few errors can you please correct this and let me know that would be helpful
Error :
Syntax error, insert “) Statement” to complete IfStatement
@BhavaniB1841
String input = “Hello World-2021”;
if (input.matches(“+$”))
{ System.out.println(“Input contains only alphabets, spaces, or hyphens”); }
else
{ System.out.println(“Input contains other characters as well”); }
BhavaniB1841
(Bhavani Basireddygari)
February 24, 2023, 1:17pm
6
@Satish Sudagoni - Thanks for the reply
it should not accept the _ and space as first character, it should accept only alphabet as first character
BhavaniB1841
(Bhavani Basireddygari)
February 24, 2023, 1:21pm
7
@MandeepRawat Thanks for the reply
but first character should be space or _ , it should be only alphabet
@BhavaniB1841 There is spelling mistake in your second screenshot
Use the code from the image I am attaching.
@BhavaniB1841
String input = “Hello World-”;
if (input.matches(“[A-Za-z -]*$”)) {
System.out.println(“Input starts with an alphabet and contains only alphabets, spaces, or hyphens”);
} else {
System.out.println(“Input does not meet the criteria”);
}
hope this helps