I must say that the question I asked can be easily run, and I have already researched it. But I want to contribute to the StackOverflow community - this is the easiest solution if you write a client validation function for an ASP.NET page.
RequiredFieldValidator is also known to trim the whitespace of a string that needs to be checked. If you look at the source of the ScriptResource.axd file associated with your application, you can find this
function RequiredFieldValidatorEvaluateIsValid(val) { return (ValidatorTrim(ValidatorGetValue(val.controltovalidate)) != ValidatorTrim(val.initialvalue)) }
and more interesting is
function ValidatorTrim(s) { var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/); return (m == null) ? "" : m[1]; }
code snippets.
So, you should not rewrite the trimmer function from scratch, you already have it and can use it.
source share