从Javascript文本框中删除制表符空间 [英] Removing tab space from text box in Javascript

查看:51
本文介绍了从Javascript文本框中删除制表符空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从文本框中删除制表符空间值.我的功能代码是:

How can I remove tab space value from a text box. My functional code is::

function validTitle() {
if (window.document.all.dDocTitle.value == "") {
alert("Please enter the Title");
window.document.all.dDocTitle.focus();
return false;
} 
return true;
}

我想再添加1个条件,以删除在window.document.all.dDocTitle.value中捕获的值的文本框中的制表符空间

I want to add 1 more condition for removing tab space in text box for value captured with window.document.all.dDocTitle.value

推荐答案

您可以使用String.trim()函数():

function validTitle() {
  // just a remark: use document.getElementById('textbox_id') instead, it's more supported
  var textBox = window.document.all.dDocTitle; 
  if (!(typeof textBox.value  === 'string') || !textBox.value.trim()) { // if textbox contains only whitespaces
    alert("Please enter the Title");
    textBox.focus();
    return false;
  } 

  // remove all tab spaces in the text box
  textBox.value = textBox.value.replace(/\t+/g,'');

  return true;
}

这篇关于从Javascript文本框中删除制表符空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆