Im so so new to php and sry for my begginer question .

<?php
        $Sal = "HI";
        if (preg_match("[a-zA-Z][a-zA-Z]",$Sal)) echo "hi";

        ?>

this is my code , why doesent the preg_match run and echo "hi"? thank you

what if you try: "/[^a-zA-Z ]/"

NO , Nothing just an empty page and know its like this with yours but no answer

<!DOCTYPE html>
<html>
    <head>


        <title></title>
    </head>
    <body>
        <p>  </p>

        <?php
        $Sal = "HI";
        if (preg_match("/[^a-zA-Z ]/",$Sal)) echo "hi";

        ?>
    </body>
</html>

ok, now I tested this and it worked

if (preg_match("/[^a-zA-Z ]/",$Sal)==0) echo "hi";

No not still

(preg_match("/[^A-Z ]/",$Sal)==0) Now everything echos like If I change $sal to hh it will echo but if you mention it should have a uppercase that it doesent have

Member Avatar for LastMitch

@kshahnazari

Try this:

<?php
$Sal = "HI";

if (preg_match ('/[a-zA-Z][a-zA-Z]$/',$Sal)) {

echo "\nhi\n"; 
  }
?>

This is, by far, my favorite site for regex testing. Make sure you use the Preg radio button, and have fun: http://www.regextester.com/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.