Did I code the regular expression correctly?

Hello,
I am coding a registration form with first name, last name, email, username and password input fields.

A. Here are my rules for a username:

  1. 5 - 10 characters.
  2. Letters: [a-z A-Z]
  3. Numbers: [0-9].
  4. Period: [.] No more than one.
  5. First & last characters must be a letter / number…

And Here is my username input field code:


<input autocomplete="off" type="text" id="username" name="username" placeholder="Username" pattern="[A-Za-z0-9]\.?[A-Za-z0-9]{5,25}">

B. Here are my rules for password:

  1. 7 characters at least.
  2. Letters: [a-z A-Z].
  3. Numbers: [0-9].
  4. At least one special character: [. $ # _ @ ! &].

Here is my username input field code:

<input type="password" id="pwd" name="pwd" placeholder=" Password"
					       pattern="[A-Za-z0-9( $ # _ @ ! &)]{7,}">

Did I code the patterns correctly ?
Are there any suggestions ? comments ?

c. What regular expresion should pattern should I use for first and last names ?

Reads as:
Exactly 1 alphanum character.
Possibly followed by a period.
Followed by somewhere between 5 and 25 alphanum characters.

Effective rules:

  1. 6-27 characters (27 only if there is a period.)
  2. The period must come second, if it exists.

reads as:
7 or more characters, any combination of alphanum, ()$#_@!& and space.

$$$$$$$ is a valid password for this rule.

Generally, you shouldnt.

Thanks for the quick answer and comments m_hutlley

I want usernames like erez.vol, arnild.s, a.schwarzenegger to be valid

does the username pattern


pattern="[[A-Za-z0-9]{1,23}\.?[A-Za-z0-9]{1,23}]{5,25}"

comply with the rules:
Username Rules

				1. 5 - 25 characters.
				2. Letters: [a-z A-Z].
				3. Numbers: [0-9].
				4. Period: [.] No more than one.
				5. First & last characters must be a letter / number..

Does the password pattern


pattern="[A-Za-z0-9]{1,}[.$# _@!&%&^*]{1,}[A-Za-z0-9]{1,}]{7,}"

comply with :

  1. 7 characters at least
  2. Letters: [a-z A-Z].
  3. Numbers: [0-9].
  4. At least one special character: [.$# _@!&%&^*].
  5. First & last characters must be a letter / number.

If not, what is the correct pattern for these rules ?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.