I have a phone number which can contain below values:
• Digits: 0-9
• Special character: "#", "*", "-", "_", " ", "(", ")", "+", "?"
• Alphabets: "x", "X"
These above can be more than once in phone number. If any other value/character besides listed in above list is present it should fail.I tried creating regex but it fails with message "Dangling meta character '*'".
Below is the regex tried:
if(!str.matches("([0-9]*|*|#|(|)|?|+|_|-)"))
{
System.out.println("--not matched--");
}
Please help me in creating a regex for above.