arenlor
04-15-2007, 08:04 AM
I have some that I keep in a text document that I'd like to share, edit them how you wish for your own keeping, and share with us your ereg codes. I'd welcome any corrections on mine.
if(!ereg("^[a-zA-Z0-9._-]+(@){1}[a-zA-Z0-9._-]{2,}(\.co)?[.]{1}(com|org|net|jp|uk|cn|ag|sc|info|biz|us|tv|ws|n ame|cc|de|be|nz|tw|jobs|eu|fm|nu|tc|tk|vg|mobi){1} $",$email)){echo"Bad";}
That one is for emails, it'll require at the bare minimum a@bc.tv and no less. I'm sure you can spend more time checking to make sure it's co.jp and that sort of thing but how I have it checks for spam entries.
if(!ereg("^[0-9]{5}((-)?[0-9]{4})?$",$zip)){echo"Bad";}
That one is for American ZIPs and requires at the least 17020 and at the most accepts 17020-1812 and also accepts 170201812 but only those three versions.
if(!ereg("^[(]?[2-9]{1}[0-9]{2}[) -.]?[0-9]{3}[- .]?[0-9]{4}[- .]?((x|ext)[.]?[ ]?[0-9]{1,5})?$",$tele)){echo"Bad";}
That's for American tele numbers, if anyone has the ereg for all international that'd be pretty cool, or if you can list your version for other countries that'd be sweet too. (If we have tele eregs from multiple countries have a radio or select list of the countries and if($country == $list/select[array]){ereg(thatcountry);}
if(!ereg("^[A-Z]{1}[a-z]+[ ]{1}[A-Z]{1}[a-z]+$",$name)){echo"Bad";}
That one checks names, bare minimum is Ab Cd. Can easily be customized to include a middle initial (add [A-Z]{1}[ ]{1} after [ ]{1})
if(!ereg("^(http://|https://){1}[a-zA-Z0-9_-.]{2,}\.(com|org|net|jp|uk|cn|ag|sc|info|biz|us|tv|w s|name|cc|de|be|nz|tw|jobs|eu|fm|nu|tc|tk|vg|mobi) {1}$",$uri)){echo"Bad";}
Checks to see if it's a valid website, notice no check for .co? Simple, [a-zA-Z0-9_-.]{2,} takes care of that. I've still to work on validating a webPAGE lol. Shouldn't be too hard, will post it tomorrow night.
if(!ereg("^image/(bmp|gif|jpeg|tiff|png)$",$_FILES['uploadedfile']['type'])){echo"Bad";}
Replace image/(name|name) with whatever type of file you want, you can do (image/(bmp|gif)|video/(mpeg|type)) also in order to allow other type of uploads.
My address ereg seems to be messed up, so I'm gonna have to fix it, I'll post it tomorrow as well, once again, America addresses.
if(!ereg("^[a-zA-Z0-9._-]+(@){1}[a-zA-Z0-9._-]{2,}(\.co)?[.]{1}(com|org|net|jp|uk|cn|ag|sc|info|biz|us|tv|ws|n ame|cc|de|be|nz|tw|jobs|eu|fm|nu|tc|tk|vg|mobi){1} $",$email)){echo"Bad";}
That one is for emails, it'll require at the bare minimum a@bc.tv and no less. I'm sure you can spend more time checking to make sure it's co.jp and that sort of thing but how I have it checks for spam entries.
if(!ereg("^[0-9]{5}((-)?[0-9]{4})?$",$zip)){echo"Bad";}
That one is for American ZIPs and requires at the least 17020 and at the most accepts 17020-1812 and also accepts 170201812 but only those three versions.
if(!ereg("^[(]?[2-9]{1}[0-9]{2}[) -.]?[0-9]{3}[- .]?[0-9]{4}[- .]?((x|ext)[.]?[ ]?[0-9]{1,5})?$",$tele)){echo"Bad";}
That's for American tele numbers, if anyone has the ereg for all international that'd be pretty cool, or if you can list your version for other countries that'd be sweet too. (If we have tele eregs from multiple countries have a radio or select list of the countries and if($country == $list/select[array]){ereg(thatcountry);}
if(!ereg("^[A-Z]{1}[a-z]+[ ]{1}[A-Z]{1}[a-z]+$",$name)){echo"Bad";}
That one checks names, bare minimum is Ab Cd. Can easily be customized to include a middle initial (add [A-Z]{1}[ ]{1} after [ ]{1})
if(!ereg("^(http://|https://){1}[a-zA-Z0-9_-.]{2,}\.(com|org|net|jp|uk|cn|ag|sc|info|biz|us|tv|w s|name|cc|de|be|nz|tw|jobs|eu|fm|nu|tc|tk|vg|mobi) {1}$",$uri)){echo"Bad";}
Checks to see if it's a valid website, notice no check for .co? Simple, [a-zA-Z0-9_-.]{2,} takes care of that. I've still to work on validating a webPAGE lol. Shouldn't be too hard, will post it tomorrow night.
if(!ereg("^image/(bmp|gif|jpeg|tiff|png)$",$_FILES['uploadedfile']['type'])){echo"Bad";}
Replace image/(name|name) with whatever type of file you want, you can do (image/(bmp|gif)|video/(mpeg|type)) also in order to allow other type of uploads.
My address ereg seems to be messed up, so I'm gonna have to fix it, I'll post it tomorrow as well, once again, America addresses.