Solved

(ASP.NET) ValidationExpression needed.

Posted on 2003-11-25
7
671 Views
Last Modified: 2010-08-05
Hi,

I need a ValidationExpression for a RegularExpressionValidator. Value must be 16 characters in length.

First character must be a letter a thru z or A thru Z    (first letter of last name)
Second character must be a letter a thru z or A thru Z  (first letter of first name)
Third chracter must be a letter m or f or M or F   (Male or Female)
Next Eight characters will hold DOB value, i.e.,  05031955 or 12211970  (DOB)
Character number 12 must be a hyphen     (-)
Last 4 characters will be last for digits of SSN  (1234)

Here is an example, SMM05031955-1234

If someone's got the time, I'd really appreciate your help.

Thanks,
Mike



0
Comment
Question by:MichaelVB
  • 3
  • 2
  • 2
7 Comments
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9820515
This regular expression does it

/[A-Za-z]{2}[MF]\d{8}-\d{4}$/
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 500 total points
ID: 9820519
sorry I meant this
/^[A-Za-z]{2}[MF]\d{8}-\d{4}$/

0
 

Author Comment

by:MichaelVB
ID: 9822663
GwynforWeb,

Hey, thanks for the input. However,  this doesn't work. I am trying to input this value and RegularExpressionValidator does not allow it:
   MSM05181966-1234

Any suggestions?

Thanks again.
Mike
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:zaratin
ID: 9823237
Hello Mike,
GwynforWeb's comment is perfectly OK. Problems may occur if you don't clear your browser's cache before loading the page again...
Anyway, here's a page that works fine with Gwyn's solution:

<% @Page Language="C#" Debug="true" %>
<script runat="server">

void Page_Load (object sender, EventArgs e)
{
  if(IsPostBack)
      {
        Validate();
        if(!IsValid)
        lab.Text="Wrong input format!";
      }
}

</script>
<html>
<body>
<form runat="server">
<ASP:TextBox runat="server" id="tb"/>
<ASP:RegularExpressionValidator runat="server" id ="regex"
         ControlToValidate="tb"
         ValidationExpression="^[A-Za-z]{2}[MF]\d{8}-\d{4}$"/>
<input type="submit"/><br/>
<ASP:Label runat="server" id="lab"/>
</form>
</body>
</html>
0
 

Expert Comment

by:zaratin
ID: 9823331
Hello Mike,
without ASP Label:
<% @Page Language="C#" Debug="true" %>
<script runat="server">

void Page_Load (object o, EventArgs e)
{
  if(IsPostBack)
      {
        Validate();
      }
}

</script>
<form runat="server">
<ASP:TextBox runat="server" id="tb"/>
<ASP:RegularExpressionValidator runat="server" id ="regex"
         ControlToValidate="tb"
         ValidatorDisplay="Dynamic"
       ValidationExpression="^[A-Za-z]{2}[MF]\d{8}-\d{4}$">
         Wrong input format!
</ASP:RegularExpressionValidator>
<br/>
             <input type="submit"/><br/>

</form>

0
 

Author Comment

by:MichaelVB
ID: 9861513
Does this cover m or f along with M or F?

I noticed that GwynforWeb's solution contains forward slashes as opposed to quotes. Will this make a difference?

Thanks for your help everyone.
0
 

Author Comment

by:MichaelVB
ID: 9861564
GwynforWeb,

Thanks for your assistance.

Mike
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP Sessions Being Cleared/Modified 6 87
Error viewing ASP page 12 173
Using Classic ASP inside HTML pages 2 62
send email part1 9 23
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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