Server Validation for six digit numbers:"\d{6}". How to avoid empty input? Thanks.

I have a server validation for ID number validation in the text box field, the regular expression is:
It works well when the user input is not exactly six digit number except it can't detext zero, i.e. when user doesn't input any thing and press enter, it will pass to the next step processing. How to change the regular expression so that it can exclude empty input?

Thanks a lot,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


First suggestion,
Why not just add a RequireFieldValidator to handle empty input.
have you thought about using a  RequiredFieldValidator ?
One advantage using RequireFieldValidator is that you can detect that the input is empty then you can give better error message.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Hi, I give it a test on with your express and don't input anything and it didn't pass.
Can you post the code ?
Nice day
heyday2004Author Commented:
Thanks a lot for the prompt responses. I wanted to know if there is any way to use only one regular expression validation here and also curious why the regular expression "\d{6}" doesn't work for empty input. Below is my code, thanks again for all the answers:

<asp:button id="btnEnter" style="Z-INDEX: 101; LEFT: 656px; POSITION: absolute; TOP: 240px" runat="server" Height="36px" Font-Size="Small" Font-Bold="True" Text="ENTER"></asp:button>

<asp:regularexpressionvalidator id="Regularexpressionvalidator2" style="Z-INDEX: 103; LEFT: 328px; POSITION: absolute; TOP: 288px" Height="24px" Runat="Server" Width="345px" Font-Size="X-Small" Text="Invalid ID number." ControlToValidate="TextBox1"  Display="Dynamic" ValidationExpression="\d{6}">Error! Shoud enter a 6 digit badge number here. <asp:regularexpressionvalidator>

Hi Heyday2004,
I think that you can't do the regular expression validate and also check null in <asp:regularexpressionvalidator control.
You should create a requiredfieldvalidator for your textbox, or you can use the custom.
<asp:CustomValidator id="valCustom" runat="server"
    ErrorMessage="*This box is not valid" dispaly="dynamic">*

'and validate what you want in ServerValidate
Sub ServerValidate (objSource As Object, objArgs As ServerValidateEventsArgs)
    ' Code goes here
End Sub
Nice day.
Hi heyday2004,

here is the remarks from MSDN :
Note   Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.

Hi heyday,
 What mmarinov said is 100% correct. You can not validate against a empty control using RegularExpressionValidator or CustomValidator or RangeValidator or any other type validator except RequiredFieldValidator. Usually when you need to use any of these mentioned validators, they should be coupled with RequiredFieldValidator, which kicks in prior to your RegularExpressionValidator, and throws an error. This is the common mistake we all do.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.