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

Is there a regular expression or someway to trim the spaces between the characters so I dont let less than 2 characters get submitted?

Here is one reg expression I tried but it let spaces between characters get entered so less than 3 characters were submitted.

/^\s+|\s+$/g,""

Do it manually. Just loop through the input and remove that character which is equal to <space> from the string and then take first 3 character for the search input string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.