CBG Posted December 15, 2010 Share Posted December 15, 2010 Hi, I currently have the below code to check the textarea box. if (preg_match("#^[a-zA-Z0-9 .,?_/'!£$%&*()+=-]+$#", $msgs)) { // Everything ok. Do nothing and continue } else { echo "Message is not in correct format.<br>You can use a-z A-Z 0-9 . , ? _ / ' ! £ $ % * () + = - Only"; However the problem is, when putting enter in the message if fails For example if I put the message this message doesnt work It fails and echo the else But if I put this message does work It is ok Could someone tell me what extra bit of code I need to add to the preg_match and where. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/ Share on other sites More sharing options...
Adam Posted December 15, 2010 Share Posted December 15, 2010 You need to add the 's' modifier after your closing delimiter: #^[a-zA-Z0-9 .,?_/'!£$%&*()+=-]+$#s Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147597 Share on other sites More sharing options...
CBG Posted December 15, 2010 Author Share Posted December 15, 2010 Thanks for the reply, I have just tried this and I get the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147603 Share on other sites More sharing options...
CBG Posted December 15, 2010 Author Share Posted December 15, 2010 I tried with m modifer but I get the reverse problem Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147604 Share on other sites More sharing options...
Adam Posted December 15, 2010 Share Posted December 15, 2010 Ah. I didn't look to much at the regex before, but you need to escape special characters to use them as literals, and since you're not using the dot to match any character (instead as a literal), you also need new line / return characters in your regex, instead of the 's' modifier. Try this: #^[a-zA-Z0-9 \.,\?_/'!£\$%&*()+=\r\n-]+$# Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147608 Share on other sites More sharing options...
Adam Posted December 15, 2010 Share Posted December 15, 2010 Also if you add "\w" (word-characters) to the regex, you can remove a-z A-Z 0-9 and _ .. to simplify it a little. Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147610 Share on other sites More sharing options...
CBG Posted December 15, 2010 Author Share Posted December 15, 2010 That worked, great thanks for the help Will look at the /w later. Thanks agin for the help Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147613 Share on other sites More sharing options...
MMDE Posted December 15, 2010 Share Posted December 15, 2010 http://www.regular-expressions.info/reference.html good site for reference Quote Link to comment https://forums.phpfreaks.com/topic/221745-preg_match-help-to-allow-enter-in-textarea-box/#findComment-1147633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.