Have to say the question I asked could be easy googled, and I have already investigated it. But I want to contribute to StackOverflow community a solution which is the simplest if you are writing a client validation function for a ASP.NET page.
It's known what RequiredFieldValidator also trims spaces of a string to be checked. If you look into the source of 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 this
function ValidatorTrim(s) {
var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null) ? "" : m[1];
}
code fragments.
So, you shouldn't rewrite trim function from the scratch, you already have it and can use it.