kee2ka4 Posted April 14, 2009 Share Posted April 14, 2009 I have the following regular expression for the body field which is a Textbox in a Form, that accept minimum 15 characters and maximum 2000 characters: $post_validation = array('body' => '/^.{15,2000}$/'); The issue I have having is, whenever I paste a large text from another website into my textbox that is below the 2000 characters, the $post_validation returns an error. I can't make out why this happens. Has anyone faced a similar problem? Thanks, Ket Link to comment https://forums.phpfreaks.com/topic/153996-reg-expression-doesnt-work-when-i-paste-text-into-textbox/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 use strlen(); function instead Link to comment https://forums.phpfreaks.com/topic/153996-reg-expression-doesnt-work-when-i-paste-text-into-textbox/#findComment-809425 Share on other sites More sharing options...
kee2ka4 Posted April 14, 2009 Author Share Posted April 14, 2009 Any reason why using Regular expression is not effective? How do I use strlen in this case. Thanks for your reply Link to comment https://forums.phpfreaks.com/topic/153996-reg-expression-doesnt-work-when-i-paste-text-into-textbox/#findComment-809432 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 strlen(); will work faster then regex. I'm not sure what the rest of your code is but you just need to do something like this... <?php if(strlen($_POST['text']) > 15 && strlen($_POST['text']) < 2000) { $post_validation = $_POST['text']; echo "that is acceptable!"; } else { echo "that is not acceptable!"; } Link to comment https://forums.phpfreaks.com/topic/153996-reg-expression-doesnt-work-when-i-paste-text-into-textbox/#findComment-809435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.