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
Release: 2016-05-16 16:45:16
Original
1943 people have browsed it
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;
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template