I need to validate a user input of about 1,500 characters
Allowed characters are a-z A-Z 0-9
Allowed symbols . , : ? ! and space
Can anyone suggest a preg_match expression for this?
I am using '/^[a-zA-Z0-9.,:?! ]+$/' but it gives error sometimes
Asked
Active
Viewed 880 times
1

Jorge
- 109
- 1
- 1
- 6
-
1That expression should work. What error are you experiencing? Do you have an example of input that should be accepted, but is not? – cdhowie Nov 17 '10 at 03:07
-
To get an answer to your question you really need to tell us what "error" you are getting. – thomasrutter Nov 17 '10 at 03:46
-
I got my answer from Ish, basically I forgot to escape \ before signs... so the error was that the preg_match was not working as initially conceived. Thanks Ish. – Jorge Nov 17 '10 at 03:59
2 Answers
-1
Use escape \ before signs
/^[a-zA-Z0-9\.\,\:\?\!]+$/'

Ish
- 28,486
- 11
- 60
- 77
-
Ish, thanks just one question, how should I add the space character to the preg_match? after the exclamation symbol? – Jorge Nov 17 '10 at 04:05
-
Ish, can you check if this is correct I added \s for whitespace and carriage returns- [a-zA-Z0-9\.\,\:\?\!\s] thanks – Jorge Nov 17 '10 at 04:38