Solved

(ASP.NET) ValidationExpression needed.

Posted on 2003-11-25
7
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 informatio…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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