Jump to content

preg_match or regx + finding "\" foreign chrs in form entrys


etnastyles

Recommended Posts

help please,

 

all this regex and preg_match is very confusing - i have been searching the net for examples but most of the ones i find relate to url searching or the [a-z] classic .

 

 

what im looking for or help with is finding characters that arent meant to be in a form that can be submitted to a mysql db i.e. \, *, +, =, -, !, ? etc.. a backslash \ preg_match would be

gd.

 

could anyone give me a pinter or point me in the correct direction.

 

thks

 

Link to comment
Share on other sites

<pre>
<?php
echo preg_match('/[^a-zA-Z0-9]/', 'Invalid string!') ? 'Invalid' : 'Valid' ;
?>
</pre>

matching numbers,characters, digits dont need regex we have ctype data to check this stuff

 

if(ctype_alnum($testcase)){
   echo 'valid';

}else{
   echo 'invalid';
}

php5 can also check email address and URL using predefined functions without using regex

Link to comment
Share on other sites

this dosnt check for werid freaky symbols like this |-_-|

 

isnt preg_match therefore better???

 

 

------------------------------code-------------------------------

<?php

$strings = array('1820.20', '10002', 'wsl!12');

foreach ($strings as $testcase) {

    if (ctype_digit($testcase)) {

        echo "The string $testcase consists of all digits.\n";

    } else {

        echo "The string $testcase does not consist of all digits.\n";

    }

}

Link to comment
Share on other sites

this code

$strings = array('1820.20', '10002', 'wsl!12','|| ');
foreach ($strings as $testcase) {
    if (ctype_digit($testcase)) {
        echo "true $testcase <br/>";
    } else {
        echo "false $testcase <br/>";
    }
}
?>

gave me this output

false 1820.20

true 10002

false wsl!12

false |-_-|

 

whats wrong with that...

I'm not saying don't use regex but dont over use regex if you only need to check numbers caracters etc..

you need php predefined functions

 

i only use regex when i'm checking for a string on pattern

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.