I googled this but it's not working fine.
Please provide me a better solution.
I use this ^([a-zA-Z]+)$
but it is not excepting single quote.
I only allow the string for example aaa'bbb
.
I googled this but it's not working fine.
Please provide me a better solution.
I use this ^([a-zA-Z]+)$
but it is not excepting single quote.
I only allow the string for example aaa'bbb
.
You can try below regex. It will take any Single Word Character (Not Whitespace) thrice and then quote and again any Single Word Character (Not Whitespace)
aaa'bbb
You need to use this "^([a-zA-Z\']+)$" as regular expression string to allow single quote in your input string.
Here is an example.
public static void main(String[] args)
{
String s= "Abc'abc";
System.out.println(s.matches("^([a-zA-Z]+)$"));//Output will be false will not allow single quote in input
System.out.println(s.matches("^([a-zA-Z\\']+)$"));//output will be true will ALLOW single quote in input
}
Best luck Anant