Skip to main content
added 457 characters in body
Source Link
kk1076
  • 1.8k
  • 14
  • 45
  • 77

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    var phn = document.getElementById('txtPhn');
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) {
        return false;
    } else {
        if (phn.value.length < 6) {
            return true;
        } else {
            return false;
        }
    }
}

EDIT:

var txtBudget = document.getElementById('MainContent_txtBudget');
    txtBudget.addEventListener('input', function (prev)
     {
        return function (evt) {
            if (!/^\d{0,6}(?:\.\d{0,2})?$/.test(this.value)) {
                this.value = prev;
            }
            else {
                prev = this.value;
            }
        };
    } (txtBudget.value), false);

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    var phn = document.getElementById('txtPhn');
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) {
        return false;
    } else {
        if (phn.value.length < 6) {
            return true;
        } else {
            return false;
        }
    }
}

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    var phn = document.getElementById('txtPhn');
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) {
        return false;
    } else {
        if (phn.value.length < 6) {
            return true;
        } else {
            return false;
        }
    }
}

EDIT:

var txtBudget = document.getElementById('MainContent_txtBudget');
    txtBudget.addEventListener('input', function (prev)
     {
        return function (evt) {
            if (!/^\d{0,6}(?:\.\d{0,2})?$/.test(this.value)) {
                this.value = prev;
            }
            else {
                prev = this.value;
            }
        };
    } (txtBudget.value), false);
format
Source Link
Yoshi
  • 54.8k
  • 14
  • 93
  • 108

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) 
 {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    var phn = document.getElementById('txtPhn');
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) 
 {
        return false;
    }
  else 
 {
        if (phn.value.length <6< 6) 
 {
            return true;
        }
  else 
 {
            return false;
        }
    }
}

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) 
 {
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('txtPhn');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57)) 
 {
return false;
}
 else 
 {
if (phn.value.length <6) 
 {
return true;
}
 else 
 {
return false;
}
}
}

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : key.keyCode;
    var phn = document.getElementById('txtPhn');
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) {
        return false;
    } else {
        if (phn.value.length < 6) {
            return true;
        } else {
            return false;
        }
    }
}
added 424 characters in body; edited tags
Source Link
kk1076
  • 1.8k
  • 14
  • 45
  • 77

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript and how to restrict user to enter only 6 digits in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) 
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('txtPhn');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57)) 
{
return false;
}
else 
{
if (phn.value.length <6) 
{
return true;
}
else 
{
return false;
}
}
}

how to restrict user to enter only numbers with two decimal values in textbox using javascript and how to restrict user to enter only 6 digits in textbox using javascript

how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??

//Function to allow only numbers to textbox
function validate(key) 
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('txtPhn');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57)) 
{
return false;
}
else 
{
if (phn.value.length <6) 
{
return true;
}
else 
{
return false;
}
}
}
edited tags
Link
Matt Burland
  • 45.3k
  • 18
  • 110
  • 182
Loading
Source Link
kk1076
  • 1.8k
  • 14
  • 45
  • 77
Loading