-2

I need to allow these special chars to be saved in the DB -> ° * : and I'm having troubles to know which part of the next string I have to remove to allow them.

private static final String ALPHANUMERIC_RE =  "^([\\w\\d_\\s\\,\\&\\/\\(\\)\\;\\\'\\\"#@\\$])*$";
alterfox
  • 1,675
  • 3
  • 22
  • 37
jose
  • 35
  • 1
  • 11

1 Answers1

0

First, ALPHANUMERIC_RE = "^([\\w\\d_\\s\\,\\&\\/\\(\\)\\;\\\'\\\"#@\\$])*$" can be shortened to:

ALPHANUMERIC_RE = "^[\\w\\s,&/();'\"#@$]*$"

They both behave the same, i.e. match strings containing the following chars:

  • any alphanumeric char, case insensitive
  • spaces and tabs
  • ,, &, /, (, ), ;, ', ", #, @, $

Now, it's esaier to understand where you should add your new chars:

ALPHANUMERIC_RE = "^[\\w\\s,&/();'\"#@$°*]*$"

sp00m
  • 47,968
  • 31
  • 142
  • 252
  • So using ALPHANUMERIC_RE = "[\\w\\s,&/();'\"#@$°*]*" would allow me to admit this chars +°: ? – jose Oct 20 '14 at 15:26
  • @jose The one you gave will allow the chars `°` and `*`. But don't forget the `^` and `$` anchors. – sp00m Oct 20 '14 at 15:32