Jump to content

Reg expression doesnt work when I paste text into textbox


kee2ka4

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.