Solved

(ASP.NET) ValidationExpression needed.

Posted on 2003-11-25
7
639 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
Comment Utility
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
Comment Utility
sorry I meant this
/^[A-Za-z]{2}[MF]\d{8}-\d{4}$/

0
 

Author Comment

by:MichaelVB
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:zaratin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
GwynforWeb,

Thanks for your assistance.

Mike
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This video discusses moving either the default database or any database to a new volume.
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.

762 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

9 Experts available now in Live!

Get 1:1 Help Now