Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate a textbox for the spaces

Status
Not open for further replies.

compu66

Programmer
Dec 19, 2007
71
US
Hi all,

I have textbox,if the user enters spaces it should throw an error.
I think it can only be possible by custom validator.Or is there any thing other way than this.

Thanks.
 
If Trim(TextBoxName.Text) == "" then
throw ex;


-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
The regualar i am using is [a-z A-Z -]{1,20},this is working good but dont handle spaces.
 
Hi,

I tried using Custom Validator handling Client and server side code.

function tbSpaces(source,args){
if(trim(txtFirstname)==""){
args.IsValid=false;}
else{
args.IsValid=true;}

}


Protected Sub tbSpaces(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
args.IsValid = True
If Trim(txtFirstName.Text) = "" Then
args.IsValid = False
Else
args.IsValid = True


End If
End Sub


But not reached the solution.

Thanks for the help in advance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top