Re: Ereg problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think this is your solution:


--------------------------------------------------------------------------------

$string = "~YOUR STRING~"

if (!eregi_replace("[0-9A-Za-z -_']","",$string))
     {
          echo "string allowed";
     }
else {
          echo "string disallowed";
 }

--------------------------------------------------------------------------------


I tested it with the following strings:

$string = "Daniel Anderson"
    Returned "string allowed".

$string = "Daniel Anderson!!"
    Returned "string disallowed".

$string = "Daniel, yo Anderson"
    Returned "string disallowed".

$string = "Daniel_Anderson-Innit"
    Returned "string allowed"

I think that may be your solution :)

Hope it helps! Try to keep all the collections like "a-z" within one set of square brackets.

Warmest Regards,
Dan


----- Original Message ----- 
From: "Beauford" <phpuser@xxxxxxxxxx>
To: <php-windows@xxxxxxxxxxxxx>
Sent: Tuesday, January 16, 2007 4:20 PM
Subject: RE:  Ereg problems


> Nope, doesn't work for me. I think what I'm trying to do must not be
> possible. I've been at this for two days now. I changed yours to this - ereg
> ("([0-9][A-Z][a-z][-_.'\ ])"  but it always says that it is invalid. The
> last one after the slash is supposed to be a space - I have to have a space.
> I don't need a length.
> 
>> -----Original Message-----
>> From: bedul [mailto:landavia81@xxxxxxxxx] 
>> Sent: January 15, 2007 11:48 PM
>> To: Beauford
>> Subject: Re:  Ereg problems
>> 
>> <?
>> $nlong=strlen($username);
>> if(ereg ("([0-9][A-Z][a-z][_-]{$nlong})", $username){
>>     echo "allowed";
>> }else{
>>     echo "disallowed";
>> 
>> }
>> 
>> //taken from ereg help
>> /*
>> if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
>>     echo "$regs[3].$regs[2].$regs[1]";
>> } else {
>>     echo "Invalid date format: $date";
>> }
>> */
>> ?>
>> 
>> ----- Original Message -----
>> From: "Beauford" <phpuser@xxxxxxxxxx>
>> To: <php-windows@xxxxxxxxxxxxx>
>> Sent: Tuesday, January 16, 2007 10:59 AM
>> Subject:  Ereg problems
>> 
>> 
>> > Hi,
>> >
>> > Without getting into a long drawn out discussion, can 
>> anyone show me a 
>> > way to validate a string that is input from a form.
>> >
>> > I want to allow the following: a to z, A to Z, 0 to 9, and "_-'" 
>> > (without the double quotes) and spaces. I have now been screwing 
>> > around with this
>> for
>> > over 8 hours. There are other issues as well that has been 
>> compoudning
>> this,
>> > but this would be a great start to solving my issue.
>> >
>> > Thanks
>> >
>> > --
>> > PHP Windows Mailing List (http://www.php.net/) To 
>> unsubscribe, visit: 
>> > http://www.php.net/unsub.php
>> >
>> 
>> 
>> 
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux