Home >Web Front-end >JS Tutorial >js method to remove all spaces in the input box and prohibit input of spaces_javascript skills

js method to remove all spaces in the input box and prohibit input of spaces_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:45:161940browse
Copy code The code is as follows:

< ;/span>

Copy code The code is as follows:

/* *
* Whether to remove all spaces
* @param str
* @param is_global If it is g or G, remove all spaces
* @returns
*/
function Trim(str,is_global)
{
var result;
result = str.replace(/(^s )|(s $)/g,"" );
if(is_global.toLowerCase()=="g")
{
result = result.replace(/s/g,"");
}
return result;
}

Copy code The code is as follows:

/* *
* Space input removal
* @param e
* @returns {Boolean}
*/
function inputSapceTrim(e,this_temp)
{
this_temp.value = Trim(this_temp.value,"g");
var keynum;
if(window .event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e. which
}
if(keynum == 32){
return false;
}
return true;
}

Copy code The code is as follows:

/**
* Disable space input
* @param e
* @returns {Boolean}
*/
function banInputSapce(e)
{
var keynum;
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/ Opera
{
keynum = e.which
}
if(keynum == 32){
return false;
}
return true;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn