Jump to content

Ereg, Eregi And Preg_match


sooty2006

Recommended Posts

i am creating a register page for a friend, but i have never used the ereg, eregi and preg_match functions before.he wants the username to contain letters, numbers and these characters (-_*space*),and the password to contain more than 6 digits, with at least one number.is there anyone that can point me in the right direction on how to do this, or maybe help me?thanks.

Link to comment
Share on other sites

For the username, the easiest way is to look for any character besides what you're allowing. The pattern for that would look like this:/[^A-Za-z0-9\-_ ]/The ^ at the start of the subpattern negates the pattern, so it looks for any characters that are not in the pattern range, which is uppercase, lowercase, numbers, and the other characters.For the password, you want to look for zero or more letters or numbers, then a number, then 0 or more letters or numbers, with a total of at least 6. That pattern looks like this:/^([A-Za-z0-9]*[0-9][A-Za-z0-9]*){6,}$/I think that should be right, there are other symbols you can use to substitute for the various ranges but I think these examples are probably easier to understand.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...