Question

Still having RegEx issues.. Need to match the following characters

a-zA-z9-0 , . ' " ( ) _ - : (SPACE)

Not all the values will have all these but could have them. I have everything withing but the parentheses, Single and Double Quoytes

/^[\w. ,\/:_-]+$/ 

UPDATE:

I got it working with this: "/^[\w. ,:()'\"-]+$/"

$val_1 = "Abh acb 123 . - _ 's ";
$val_2 = "Asc";
$val_3 = "234";
$val_4 = "nj%"; // Fail
$val_5 = "Help (me)";
$val_6 = "What's wrong?"; // Fail
$val_7 = "She's here";
$val_8 = "No: 123.00, 432.00";
$val_9 = 'Need to " Double" ';

$var_array = array($val_1, $val_2, $val_3, $val_4, $val_5, $val_6, $val_7, $val_8, $val_9);

foreach ($var_array as $k=>$d) {
    if ((preg_match("/^[\w. ,:()'\"-]+$/", $d))) {
        echo "Yeah it matches!!!<span style='color:green'>".$d."</span><br />";
    } else {
        echo "Try again, thie FAILED<span style='color:red'>".$d."</span><br />";
    }
}

Thanks for all for helping out

Was it helpful?

Solution 4

With the help of the other submitting I have found the solution that works:

"/^[\w. ,:()'\"-]+$/"

Thanks to all for the help

OTHER TIPS

$pat = "/^[\w. ,\\/:_()'\"-]/";

To match all those, you just need:

preg_match("/[a-zA-Z0-9,.'\"()_- :]/", $string);
/^[-a-zA-Z0-9,.'"()_: ]+$/ 

This should work. But if you put it into a string be sure to escape the needed quotes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top