0

I want a regular expression in java which should allow alphabets,number and comma. Could anyone please help? I am using the code. But it is not working

Pattern p = Pattern.compile("^[A-Za-z0-9,]$", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(object.toString());
boolean bcheck = m.find(); 
scopchanov
  • 6,933
  • 10
  • 30
  • 56
  • You may use `boolean bcheck = object.toString().matches("[A-Za-z0-9,]+")` – Wiktor Stribiżew Sep 17 '18 at 13:45
  • Thank you for your reply. But this expression is allowing all special characters also. I need an expression which strictly allow only alphabets,numbers and comma.For example it should allow all the below patterns : – Mamatha Reddy Sep 18 '18 at 07:28
  • You are wrong. You did not even try my solution. `.matches` requires a full string match. Do not use `.find()`. – Wiktor Stribiżew Sep 18 '18 at 07:29

0 Answers0