validating a field - regex validator or custom validator??

I am creating an account creation page using 2.0/C#.

For the username, I have a textbox for username. I also have a dropdown list next to it that has around 10 different domains.

So the actual e-mail address will be something like:
   txtUserName.txt + '@' + lstDomains.SelectedItem.Value

The rules I have to follow are as follows:

·        50 characters max (this includes the '@' symbol and the text from the domain dropdown - the length of the domain will be different)
·        No UNICODE
·        First char must be a letter (must be in ASCII code range of 97-122, 65-90)
·        Period ‘.’ (ASCII 46) allowed except for the first and last characters but cannot have two adjacent periods
·        All other chars must be in ASCII code range of 48-57 (numbers), 65-90 (uppercase), 95 (underscore), 97-122 (lowercase)

Can someone please please help me write a regex for a RegularExpressionValidator?
Its its too hard or impossible, please help me with a CustomValidator.

I might end up allocating 10 characters for the domain name and the rest for username if things get too complicated.

Who is Participating?
pauljk1619Connect With a Mentor Commented:
Not sure if you wanted to validate the @ and the domain since it was coming from a drop down.  

This is for the UserID part.  Did you want to validate the domain as well?


IUAATechAuthor Commented:
Nope, I don't need to validate the @ and the dropdown. Will your regex take into consideration that the email address can be at most 50 characters long? This includes the @ and the text from the dropdown.
I don't know how to limit the length of the entire result.  I can limit the size of the of the parts.  This should do everything except the < 51 size.  


Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

IUAATechAuthor Commented:
I think its will make my life easier if I assume that the string '@domain' will have a max length of 15 characters.

Then I can use your original regex and change the {2,50} to {2,35}.

What do you think?
I think that works, especially since you are in control of the length of the doman names, correct?
IUAATechAuthor Commented:
yes. correct.

thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.