expression issue

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

expression issue

Post by itsmani1 »

Hi all

I am having an expression issue, this code works fine but if i tired testing it using form it don't work.

Code: Select all

$regex='/^[a-zA-Z0-9_\.\-\;\:\'\"\/ ]{5,95}$/';
echo preg_match($regex, 'NEW Sony\'s 3.0" L.C.D. - 12MP DIGITAL CAMERA/VIDEO/TOUCH SENSOR K38');
here is my form code:

Code: Select all

<form id="form1" name="form1" method="post" action="test1.php">
  <input name="textfield" type="text" value="NEW Sony\'s 3.0" L.C.D. - 12MP DIGITAL CAMERA/VIDEO/TOUCH SENSOR K38" size="75" />
  <input type="submit" name="Submit" value="Submit" />
</form>
on submit this will give me 0.

any help

thank you
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Note the double quote in the middle of the value in the form data. Also note the backslash before the single quote in the same value of the form.

Your regex attempts to match the entire input; it breaks at the backslash.
Post Reply