MichaelVB
asked on
(ASP.NET) ValidationExpression needed.
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
I need a ValidationExpression for a RegularExpressionValidator
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Hey, thanks for the input. However, this doesn't work. I am trying to input this value and RegularExpressionValidator
MSM05181966-1234
Any suggestions?
Thanks again.
Mike
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:RegularExpressionVali dator runat="server" id ="regex"
ControlToValidate="tb"
ValidationExpression="^[A- Za-z]{2}[M F]\d{8}-\d {4}$"/>
<input type="submit"/><br/>
<ASP:Label runat="server" id="lab"/>
</form>
</body>
</html>
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:RegularExpressionVali
ControlToValidate="tb"
ValidationExpression="^[A-
<input type="submit"/><br/>
<ASP:Label runat="server" id="lab"/>
</form>
</body>
</html>
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:RegularExpressionVali dator runat="server" id ="regex"
ControlToValidate="tb"
ValidatorDisplay="Dynamic"
ValidationExpression="^[A- Za-z]{2}[M F]\d{8}-\d {4}$">
Wrong input format!
</ASP:RegularExpressionVal idator>
<br/>
<input type="submit"/><br/>
</form>
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:RegularExpressionVali
ControlToValidate="tb"
ValidatorDisplay="Dynamic"
ValidationExpression="^[A-
Wrong input format!
</ASP:RegularExpressionVal
<br/>
<input type="submit"/><br/>
</form>
ASKER
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.
I noticed that GwynforWeb's solution contains forward slashes as opposed to quotes. Will this make a difference?
Thanks for your help everyone.
ASKER
GwynforWeb,
Thanks for your assistance.
Mike
Thanks for your assistance.
Mike
/[A-Za-z]{2}[MF]\d{8}-\d{4