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 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 use strlen(); function instead Quote Link to comment 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 Quote Link to comment 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!"; } Quote Link to comment 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.