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

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!";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.