I want to validate: NEW Sony's 3.0" L.C.D. - 12MP DIGITAL CAMERA/VIDEO/TOUCH SENSOR K38 Here is my expression: $regex='/^[a-zA-Z0-9_\.\-\;\:\'\"\/ ]{5,95}$/'; PHP: Please help
Yes, I tried this and it's working: $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'); PHP: However, you don't have to escape all these characters. This is the same: $regex = '/^[\w-\.;:\'"\/ ]{5,95}$/'; PHP: Both work for me. (tested)
Well it works file but if if is post via form i gets problem. any solution to that, I also tired: htmlspecialchars and addslashes Here is my code: $regex='/^[a-zA-Z0-9_\.\-\;\:\'\"\/ ]{5,95}$/'; echo htmlspecialchars('NEW Sony\'s 3.0" L.C.D. - 12MP DIGITAL CAMERA/VIDEO/TOUCH SENSOR K38');exit; $txt = htmlspecialchars($_POST["textfield"]); echo $txt."<BR>"; echo preg_match($regex, $txt); PHP: <form id="form1" name="form1" method="post" action="test1.php"> <input name="textfield" type="text" value="<?PHP echo $_POST["textfield"]; ?>" size="75" /> <input type="submit" name="Submit" value="Submit" /> </form> Code (markup):