how to accept only number and + symbol

Posted by Deepakji under C# on 4/3/2012 | Points: 10 | Views : 797 | Status : [Member] | Replies : 5
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 and i am writing it in onkeypress




Responses

Posted by: Self-Innovator on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
hi...count the ASCII Character value of(+) and set the condition....If it is less than 1 then proceed...

Join Hands Change lives
Thanks & Regards
Straight Edge Society

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

Posted by: Deepakji on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
it should only have + once and two number where max limit of box is 3 means like question marks [3+4] in that format and not accept more than one + and not accept all number and not accept all + so these are the condition in that

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

Posted by: Self-Innovator on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Try wit this....
function EnterOnlyNumbers(x)

{
var len=x.value.length;//if len is 2 then check for the Second value
var s_charcode=0;
var specialSymbol;
for(var s_i=0;s_i<len;s_i++)
{
s_charcode=x.value.charCodeAt(s_i);
specialSymbol=x.value.charCodeAt(1);
if(!((s_charcode==43)
{
alert("Second charcter shud be +");
return false;
}
if(!((s_charcode>=48 && s_charcode<=57)))
{
alert("Enter only numbers");
x.value="";
x.focus();
return false;
}
}
return true;
}

Call this in OnChange Event of txtBox..
<asp:textbox id="txt1" ruat="server" onChange="EnterOnlyNumbers(this)">

Join Hands Change lives
Thanks & Regards
Straight Edge Society

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

Posted by: Sabarimahesh on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Self-Innovator


You Are posted Nice Example


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: Deepakji on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
Error 13 'ASP.adminmodifybank_aspx' does not contain a definition for 'EnterOnlyNumbers' and no extension method 'EnterOnlyNumbers' accepting a first argument of type 'ASP.adminmodifybank_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Inetpub\wwwroot\qbgs copy\AdminModifyBank.aspx


(this is error we are getting

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

Login to post response