<script language=”javascript”>
/**
*
刪除左右兩端的空格
*/
String.prototype.trim=function()
{
return
this.replace(/(^/s*)(/s*$)/g, ”);
}
/**
*
刪除左邊的空格
*/
String.prototype.ltrim=function()
{
return
this.replace(/(^/s*)/g,”);
}
/**
*
刪除右邊的空格
*/
String.prototype.rtrim=function()
{
return
this.replace(/(/s*$)/g,”);
}
</script>
運用示例如下:
<script
type=”text/javascript”>
alert(document.getElementById(’abc’).value.trim());
alert(document.getElementById(’abc’).value.ltrim());
alert(document.getElementById(’abc’).value.rtrim());
</script>