Solved

RegularExpressionValidator - Numeric 13 characters

Posted on 2008-10-09
10
643 Views
Last Modified: 2013-12-17
New-ish to regular expressions and this is driving me nuts.  I've got a RegularExpressionValidator and I need the input to be a number at least 13 characters long.  I'm sure this is a snap but I cannot get it right.

TIA,

N
0
Comment
Question by:stretch73
10 Comments
 
LVL 11

Assisted Solution

by:fanopoe
fanopoe earned 100 total points
ID: 22680485
this should get you started:

"\d{13}"

see below usage


hth
<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="rev01" runat="server" ControlToValidate="txtTest" Text="Error" ValidationExpression="\d{13}">

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22680493
Will this do?
^[1-9]\d{12}$
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22680494
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 22

Expert Comment

by:prairiedog
ID: 22680511
@fanopoe:
\d{13} will take "0000000000000", or "0100000000000", etc,  as valid numbers,
0
 

Author Comment

by:stretch73
ID: 22680539
This did not work:

<asp:RegularExpressionValidator ID="rfvBillingAccountNumber"
                                    ControlToValidate="txtBillingAccountNumber"
                                    ValidationExpression="^[1-9]\d{12}$"
                                    ErrorMessage="A billing account number must be 13 digits, numeric, and is required to add a customer."
                                    Display="dynamic"
                                    runat="server"/>
0
 

Author Comment

by:stretch73
ID: 22680549
Thank you for the suggestions, but will these also validate against no input either?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22680552
After reviewed the original question, I changed my expression to this:
^[1-9]\d{12,}$  ''<== Added a comma to meet the requirement: at least 13 characters long
Note: [1-9] will ensure that numbers with leading 0 are not allowed.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22680566
You will need a RequiredFieldValidator again no input value.
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 400 total points
ID: 22680586
Your error message says "A billing account number must be 13 digits, numeric, and is required to add a customer.". It does not match your original requirements: at least 13...
My first solution matches numbers with exactly 13 digits, and the modified solution matches numbers with at least 13 digits.
0
 

Author Closing Comment

by:stretch73
ID: 31504736
Thanks PD and fanopoe, exactly what I needed.

N
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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