<input type="text" name="mytext" id="mytext"/>
the old way to get value and trim
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
var textvalue = trim(myform.mytext.value);
the new way:
var textvalue = $.trim(('#mytext').val());
the old way to get value and trim
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
var textvalue = trim(myform.mytext.value);
the new way:
var textvalue = $.trim(('#mytext').val());
Comments
Post a Comment