Reputation: 95
I have a view where in textbox user enters a value. It may be number, character, special character anything. But I want to validate that user is not allowed to enter ONLY spaces. User can enter spaces with characters, but ONLY spaces are not allowed.
For eg.
User can enter Name : Stack ""space" Overflow
but user should not be allowed to enter
Name : "space" "space" "space"
Problem is I cant check it server side as my models are DTO defined in another project which is loaded as dll in this one.
Upvotes: 0
Views: 1995
Reputation: 918
Define a trim function in Javascript. More information can be found here: Trim string in JavaScript?
Upvotes: 1
Reputation: 172418
You can try this
bool b= textBox1.Text.Length>0 && textBox1.Text.Trim().Length==0;
Upvotes: 1
Reputation: 295
Could you not trim the text and check if the length is greater than zero?
Upvotes: 1