Solved

(ASP.NET) ValidationExpression needed.

Posted on 2003-11-25
7
688 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

628 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