Regular Expressions

A

Arpan

A Web control like a textbox can be validated using Regular Expressions like the following:

<form runat=server>
Name: <asp:TextBox id="txtName" runat=server/>
<asp:RequiredFieldValidator ControlToValidate="txtName" ErrorMessage="Please enter your name!" Display="Dynamic" runat=server/>
............
.............
</form>

In the above code, users will be alerted immediately if they don't enter their name. ASP.NET will not allow the Form to be posted if the Name textbox is empty & hence no info will be sent back & forth from the server to validate the textbox.

Now the same Form can be created using the textbox HTML Server control like the following:

<form runat=server>
<input type=text name="txtName" id="txtName" runat=server>
............
.............
</form>

Can the 2nd Form be validated using Regular Expressions in the same way as what has been done in the 1st Form? If no then how to validate the 2nd Form so that users are alerted immediately if they leave the textbox empty?

Thanks,

Arpan
 
A

Arpan

I am very sorry Patrick. I should have tried it out first before posting my query. I sincerely apologize for the folly.

Anyway, Regular Expressions do work with HTML Server controls in the same way as they do with Web controls!

Sorry once again & thanks for pointing it out,

Regards,

Arpan
Arpan why don't you try it since you are using the same id="txtName"!
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top