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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim space attempt 1

Status
Not open for further replies.

cleanair4me

Technical User
May 16, 2008
61
0
0
I want to make sure at least 3 characters are entered into a search field.
For example I dont want this to go by where it has spaces in beginning and space between 2 characters: a b

I tried the below regular expression but it didnt capture the spaces in between the characters. Please advise how I can do it?
Code:
/^\s+|\s+$/g,""
 
>/^\s+|\s+$/g,""
In what context this expression is taken from?
 
I guess this is what you are after.
[tt]
s=" a b"; //retrieve from some element
var am;
am=s.match(/\S/g);
if (am!=null && am.length>2) {
return true; //validated
} else {
return false; //invalidated
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top