?
Solved

validating a field - regex validator or custom validator??

Posted on 2006-05-02
6
Medium Priority
?
333 Views
Last Modified: 2012-08-13
I am creating an account creation page using asp.net 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.

Thanks.
0
Comment
Question by:IUAATech
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
pauljk1619 earned 1200 total points
ID: 16591462
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?

^(([a-z,A-Z]+[._])*[0-9a-zA-Z]{2,50})$

0
 

Author Comment

by:IUAATech
ID: 16596018
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.
0
 
LVL 7

Expert Comment

by:pauljk1619
ID: 16598400
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.  

^(([a-zA-Z]+[._])*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]$

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:IUAATech
ID: 16598426
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?
0
 
LVL 7

Expert Comment

by:pauljk1619
ID: 16598509
I think that works, especially since you are in control of the length of the doman names, correct?
0
 

Author Comment

by:IUAATech
ID: 16598570
yes. correct.

thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 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