Reputation: 141
I have a wepage for a user to sign up,i have tested it and runned it,i was testing it using space not entering any words to signup,meaning a user can signup without entering any words just by using space.so i dont want this to happen to my webpage.
any one who has some code that i can use to validate this...
Upvotes: 0
Views: 95
Reputation: 3653
either the simple string.IsNullOrWhiteSpace
or if you really want to use the answer you chose, you should edit it to:
if (firstName ! = null && lastName ! = null)
{
if (firstName.Trim()=="" || lastName.Trim()=="")
{
return False;
}
else
{
return True;
}
}
else return False;
Upvotes: 0
Reputation: 12737
you can validate user input in many ways. One of them is to use built in Visual Studio Vaidator controls and make sure that each control is tighed to a text box in your form and its preoperty is selected to ensure the field is filled before submitting the form.
Another way is to do the validation from the code behind. Something like this:
if (firstName.Trim()=="" || lastName.Trim()=="")
{
return False;
}
else
{
return True;
}
Upvotes: 0