-3

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.

asontu
  • 4,264
  • 1
  • 17
  • 25
van
  • 1
  • 2

2 Answers2

0

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

disp_name
  • 1,186
  • 1
  • 16
  • 38
0

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