I want to write a regular expression in java which will accept the String having alphabets, numbers, - and space any number of times any where.
The string should only contain above mentioned and no other special characters. How to code the regular expression in java?
I tried the following, It works when I run it as a java application.
But the same code when I run in web application and accept the values through XML, It accepts '/'.
String test1 = null;
Scanner scan = new Scanner(System.in);
test1 = scan.nextLine();
String alphaExp = "^[a-zA-Z0-9-]*$";
Pattern r = Pattern.compile(alphaExp);
Matcher m = r.matcher(test1);
boolean flag = m.lookingAt();
System.out.println(flag);
Can anyone help me on this please?