JavaScript to Validate the Money Field :-)

A

Abhishek

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 :)
 
T

Thomas 'PointedEars' Lahn

Abhishek said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top