Skip to content Skip to sidebar Skip to footer

Removing Tab Space From Text Box In 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');

Solution 1:

You can do this by using String.trim() function () :

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;
}

Post a Comment for "Removing Tab Space From Text Box In Javascript"