validating a field - regex validator or custom validator??

Posted on 2006-05-02
Last Modified: 2012-08-13
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.

Question by:IUAATech
    LVL 7

    Accepted Solution

    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?



    Author Comment

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

    Expert Comment

    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.  



    Author Comment

    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?
    LVL 7

    Expert Comment

    I think that works, especially since you are in control of the length of the doman names, correct?

    Author Comment

    yes. correct.

    thanks for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now