I would like to implement credit card txtbox where the user can input numbers only, and a hyphen after every 4 numbers is auto inserted (I am doing the auto-insertion correctly, its working). But if the user tries to enter alphabets those shouldn't be allowed,
I know about regular expression validators, but I want that user shouldn't be able to key in the alphabets at all
I would like to implement credit card txtbox where the user can input numbers only, and a hyphen after every 4 numbers is auto inserted (I am doing the auto-insertion correctly, its working). But if the user tries to enter alphabets those shouldn't be allowed,
I know about regular expression validators, but I want that user shouldn't be able to key in the alphabets at all
Hi mamoorkhan,
Your problem completely resolved after using code from that link.
I would like to implement credit card txtbox where the user can input numbers only, and a hyphen after every 4 numbers is auto inserted (I am doing the auto-insertion correctly, its working). But if the user tries to enter alphabets those shouldn't be allowed,
I know about regular expression validators, but I want that user shouldn't be able to key in the alphabets at all
That solution also allows the user to key in special characters and alphabets, and my client's requirement is that the user shouldn't be able to key in nything other than a number
That solution also allows the user to key in special characters and alphabets, and my client's requirement is that the user shouldn't be able to key in nything other than a number
Hi mamoorkhan,
Have you tried @urenjoy mentioned link, that will help you to do so. Checkout his mention link and let us know if any query remains.
thanks for your kind responses I wasn't able to get back here due to busy schedule, anyhow that problem is solved, I am now using the credit card validator found here http://www.braemoor.co.uk/software/creditcard.shtml.
It takes care of all the validation of credit card number format and I am using another script for not allowing the user to enter anything other than numerics, via capturing the event keycodes and returning false if the keycode is anything other than numeric
or backspace. Now another problem arises that is that CTRL + V is not working in Firefox, though the CTRL + V is working fine in other major browsers like IE, Safari and Chrome (Haven't tested on opera).
Anyone knows how to allow for pasting in the txtbox in Firefox???
function numericMasking(input, textbox, e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if ((keycode < 48 || keycode > 57) && (keycode != 8)) {
return false;
} else {
textbox.value = input;
}
}
mamoorkhan
Member
64 Points
52 Posts
Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 06:45 AM|LINK
I would like to implement credit card txtbox where the user can input numbers only, and a hyphen after every 4 numbers is auto inserted (I am doing the auto-insertion correctly, its working). But if the user tries to enter alphabets those shouldn't be allowed, I know about regular expression validators, but I want that user shouldn't be able to key in the alphabets at all
matifnadeem
Contributor
4722 Points
1112 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 07:02 AM|LINK
Hi mamoorkhan,
Your problem completely resolved after using code from that link.
It is perfectly match what you need. Let me know if any query still remains
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
urenjoy
Star
12367 Points
1862 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 07:03 AM|LINK
You can use jQuery MASK plugin
matifnadeem
Contributor
4722 Points
1112 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 07:26 AM|LINK
Hi mamoorkhan,
You already got the right answer, visit
Why you create same post here?
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
mamoorkhan
Member
64 Points
52 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 09:08 AM|LINK
That solution also allows the user to key in special characters and alphabets, and my client's requirement is that the user shouldn't be able to key in nything other than a number
Maheshkumarp...
Member
366 Points
117 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Jan 31, 2013 10:37 AM|LINK
Hi,
try this one
<html>
<head>
<title>Javascript Validation for Credit card Number</title>
<script type="text/javascript">
function mask(textbox, e) {
var charCode = (e.which) ? e.which : e.keyCode;
if (charCode == 46 || charCode > 31
&& (charCode < 48 || charCode > 57)){
alert("Only Numbers Allowed");
return false;
}
else{
if (textbox.value.length == 4 || textbox.value.length == 9 || textbox.value.length == 14) {
//keycode to avoid response to backspace
if (e.keyCode != 8) {
textbox.value = textbox.value + '-';
}
}
return true;
}
}
</script>
</head>
<body>
<div>
<input type="textbox" onblur="return mask(this,event);" onkeypress="return mask(this,event);"></input>
</div>
</body>
</html>
"Please Mark As Answer, If u find Helpful."
matifnadeem
Contributor
4722 Points
1112 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Feb 01, 2013 05:48 AM|LINK
Hi mamoorkhan,
Have you tried @urenjoy mentioned link, that will help you to do so. Checkout his mention link and let us know if any query remains.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
Ruchira
All-Star
43056 Points
7040 Posts
MVP
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Feb 04, 2013 05:26 PM|LINK
Hello,
You can use AJAX MaskedEditExtender.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.roopeshreddy
All-Star
20155 Points
3328 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Feb 05, 2013 10:53 AM|LINK
Hi,
I blogged the same here - http://roopeshreddy.wordpress.com/2012/06/09/asp-net-sever-controls-validation-using-javascript-jquery/
Not allowing users to enter any keys other than Numerics!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
mamoorkhan
Member
64 Points
52 Posts
Re: Javascript Numbers only textbox (with hyphens also, e.g. credit card)?
Feb 06, 2013 01:06 PM|LINK
Hi All,
thanks for your kind responses I wasn't able to get back here due to busy schedule, anyhow that problem is solved, I am now using the credit card validator found here http://www.braemoor.co.uk/software/creditcard.shtml. It takes care of all the validation of credit card number format and I am using another script for not allowing the user to enter anything other than numerics, via capturing the event keycodes and returning false if the keycode is anything other than numeric or backspace. Now another problem arises that is that CTRL + V is not working in Firefox, though the CTRL + V is working fine in other major browsers like IE, Safari and Chrome (Haven't tested on opera).
Anyone knows how to allow for pasting in the txtbox in Firefox???
function numericMasking(input, textbox, e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if ((keycode < 48 || keycode > 57) && (keycode != 8)) { return false; } else { textbox.value = input; } }