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