I have a javascript regex
Value.match(/[A-Za-z0-9\-\,\.\(\)/]/)
This gives me 1 if a string contains alphabets, numbers, hyphen, comma, dot or braces; if any other character is found it gives 0.
When I apply same regex in PHP it is not working. Why?
You don’t need to escape characters inside
[]so you can try this/[A-Za-z0-9,.()]/or even this one/[\w,.()]/but if you want to check that the string contains only those characters that regex won’t do, try:I noticed that you also have
/. Is that intentional or a mistake, because you don’t mention it in the question…