hi all

i want to limit the input from the user in the textbox... actually i am creating a "signup" page where the user have to type his name ,password, email, etc...

the problem is i want an error to be displayed on a label when the user type nothing in the name for example says that "please fill the empty fields" and also i want an error to be displayed if the user include "\,&,^,%,$,#,|,<,>" in his name says for example "only letters and numbers allowed to be written in name field"

i tryed this could:

if txtname.text = "" then
lblinvalid.text="please fill the empty fields"
end if

but it didn't work i dont know why??!!!!!!

and also how to limit the text to only numbers and letters without these characters "\,&,^,%,$,#,|,<,>"???

thanks all

Hi, I'm really just getting back into it but I'll venture with an answer:

for the empty string have you looked at using a RequiredFieldValidator?

if you use this:

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server"
ErrorMessage="Enter your firstname" ControlToValidate="yourcontrolID">

It would display the error message if blank (there's more options with this of course)

For the caracters limitation you can use a RegularExpressionValidator:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="RegularExpressionValidator"

This example is a pre-done email format validator but you can make any ValidationExpression.
Searching on the net I've come accross a Regular Expression cheat sheet that explains how to use that (not obvious but effective)

That will validate during input and you can use a !Page.IsValid to make sure it won't go through or just disable the submit button until valid.

Hope it helps

hmmmm...not that clear

but ok

the thing is i am using VS VB.net 2005 and am using normal text box and label for validation i didnt go for "validation Control" coz i feel am more flexible this way

so, any idea how to do it manually without the "validation control" use?

it will benefit me also to know how its work

The RequiredFieldValidator is a control - just like a label - that sits there waiting for the control to be changed.

You can add it in your ASP code just like above:

[LEFT]<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server"
ErrorMessage="Enter your firstname" ControlToValidate="yourcontrolID">

or drop it in your designer form from the toolbox in VS 2005

the property ControlToValidate is in reference to your textboxID - let's say tbLogin - it binds the validator to your textbox waiting for input. If the textbox is unchanged (you can set a default value) or if it is changed back to the initial value (let's say blank - "") it will display the error message (in red by default). You can even add code in your class to do whatever you want, like enable the button submit when it is valid.

It's pretty much the same with RegularExpressionValidator but it will use this "RegularExpression" to make sure the input string is valid (using the weird code). You can force a alpha-numeric string or an email format or even a phone number format.

I really think this is what you are looking for, I've used it for login purposes (for tests) and it worked well for me in c#. In any case, I think it is definitely worth looking it up!

And I forgot, the reason why your code did not work was probably because you did not add an eventhandler to your code

Now I do this using C# code but it should be similar - if not the same - in VB . Anyways you can use the asp code as well.

if you double-click on you textbox in your designer form it will create an EvenHandler method -
in C#

protected void TextBox1_TextChanged(object sender, EventArgs e)

as you can see it is triggered by a change in the text - so it is dynamic. in there you can put your code above and it will work. Also note that in your asp form, you textbox declaration will change to something like this


Adding the method to call if the text is changed.

Hope it helps