By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

JavaScript to Validate the Money Field :-)

P: n/a
Hi I have tried one more javascript Validator Script to Validate the
Money entered in to the TextBox.

<script language='javascript'>
function checkNumber(val,e){
if(window.event){
var strkeyIE = e.keyCode
if(((strkeyIE >= 48) && (strkeyIE <= 57 )) || (strkeyIE == 44) ||
(strkeyIE == 36) ){}
else{
return false;}}
else{
var strkeyCode = e.keyCode
var strCharCode = e.charCode
if(((strCharCode >= 48) && (strCharCode <= 57 )) || (strCharCode ==
44) || (strCharCode==36)|| (strkeyCode==37 )|| (strkeyCode==38) ||
(strkeyCode == 46)||(strkeyCode==8 ) || (strkeyCode ==9 ) ||
(strkeyCode==39) || (strkeyCode ==35) || (strkeyCode ==36) ||
(strkeyCode==9)){}
else{return false;} }
return true;}
function valFuncReg_Money(text,reg){
if(text == null || text == '')return true;
if(reg == null || reg =='')return true;
var regex = new RegExp(reg);var value=text;
var res= (regex.exec(text));
if(res==null){
reg =/^\$?[0-9]+$/;
regex = new RegExp(reg);
res= (regex.exec(text));}
return (res != null && value == res[0]);}
</script>
The above script can be called on "Onkeypress" event of the TextBox as
follows :

"Onkeypress", "javascript:return checkNumber(this,event);"
Please feel free to give Comments and Suggessions and Bugs also :-)

Aug 5 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Abhishek wrote:
Hi I have tried one more javascript Validator Script to Validate the
Money entered in to the TextBox.
[...]
Try another one, after you got a minimum clue.
The above script can be called on "Onkeypress" event of the TextBox as
follows :

"Onkeypress", "javascript:return checkNumber(this,event);"
Certainly not.

1. There is no `Onkeypress' event. The event is called `keypress', if that.
2. This is not proper/meaningful syntax in any language.
3. Assuming this is supposed to resemble HTML:
<http://jibbering.com/faq/#FAQ4_24>
4. The local `event' property is proprietary, it can be used but needs
to be feature-tested before.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.