Accepting number and +symbol only

Posted by Deepakji under JavaScript on 4/3/2012 | Points: 10 | Views : 1230 | Status : [Member] | Replies : 1
function isNumberPlusKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)&&charCode!=43)
return false;

return true;
}

this is the code where it is accepting the number and '+'symbol but now it should accept only once '+' and two number ex(5+2,12,3+5,) but not(2++,++4,+++,333) here i have given textbox limit three so please let me know how to do that its urgent




Responses

Posted by: Rajni.Shekhar on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Write a function to check plus sign occurrance, onBlur event on textbox

function checkSign(strString, txtBoxID){
var currIndex;
var lastIndex;
currIndex=strString.indexOf('+');
lastIndex=strString.lastIndexOf('+');
if(currIndex!=lastIndex)
{
alert('More than one plus sign is not allowed.');
document.getElementById(id).value='';
document.getElementById(id).focus();
return false;
}
}

Thanks,
Rajni Shekhar

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response