Jump to content

Validation problems


SyncViews

Recommended Posts

Ive got this validation code

 

function valid($string, $type)
{
switch ($type)
{
	case "name":
		$allowed = preg_match("|^[A-Z0-9\ _]{3,16}$|i", $string);
		break;

	case "password":
		$allowed = preg_match("|^[A-Z0-9_]{6,40}$|i", $string);
		break;

	case "email":
		$allowed = preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z.]{2,6}$|i", $string);
		break;
}
return ($allowed);
}

1) For the password one. How do I make it so it allows 6 or more charecters?

 

2)For e-mails it always returns false. Why is this?

Link to comment
https://forums.phpfreaks.com/topic/81953-validation-problems/
Share on other sites

Q1: Use {6,} instead of {6,40}

 

Q2: A-Z will only accept uppercase characters (that's actually a "bug" in all the regular expressions in your code (unless of course you only want your users' passwords and usernames to have uppercase characters, underscore and numbers)). You need to specify both the uppercase characters and lowercase characters (i.e. a-zA-Z).

Link to comment
https://forums.phpfreaks.com/topic/81953-validation-problems/#findComment-416379
Share on other sites

The one I got from that p[age is basicle the same as mine and still isn't working for me :(

 

mine:

$allowed = preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$|i", $string);

 

the one I made useing the sites examples:

$allowed = preg_match("|$[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i", $string);

 

Mayby it's my php code? But if thats the case whyt would both the user name and password ones work...

Link to comment
https://forums.phpfreaks.com/topic/81953-validation-problems/#findComment-416407
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.