0

i have the following regex in place to validate the name field in my program and it works fine

^[a-zA-Z\\d\\s_.@\\-]*$

{"name":"jfhgjhf"}

I now want to add an embedded json element that I am passing in as part of my json (I am using Schema Form) I want my taskDetails element to accept the same charachters as name as well as the charachters {[/:="

I tried the following regex with no joy

^[a-zA-Z\\d\\s_.@\\-{\\]\\[}/\\\\/\\/ ':=]*$

{"name":"jfhgjhf","taskDetails":"{\"ids\":[{\"id\":\"jhgjghjghfjf\"}]}"}

Any help on this would be greatly appreciated

Thanks Damien

Damien
  • 4,081
  • 12
  • 75
  • 126
  • 3
    Why don't you use a [JSON parser](http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java)? – Sam Mar 31 '15 at 19:15
  • its not possible or doesnt make sense in this project. I want to store the json in 1 field in my db table .It makes sense for my project and how I am using schema form – Damien Apr 04 '15 at 16:36

1 Answers1

2

This will do the work

^[a-zA-Z\d\s_.@{\\}\/ ':=",\[\]-]*$

- must be final char because it can recognize for example a-z

http://regexr.com/

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
  • 4
    @FlorianLefèvre `.` doesn't need to be escaped (it has no special meaning in a character class). `-` does not need to be escaped, like OP mentions, at the beginning or end of a character class since `[-x]` and `[x-]` are obviously not ranges. – Sam Mar 31 '15 at 19:38
  • 2
    You're right, in character class `.` has no special meaning... Learned something today ! :) Thanks. – fdglefevre Mar 31 '15 at 19:44