JavaScript to Validate the Money Field :-)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abhishek

    JavaScript to Validate the Money Field :-)

    Hi I have tried one more javascript Validator Script to Validate the
    Money entered in to the TextBox.

    <script language='javas cript'>
    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(((strCharCod e >= 48) && (strCharCode <= 57 )) || (strCharCode ==
    44) || (strCharCode==3 6)|| (strkeyCode==37 )|| (strkeyCode==38 ) ||
    (strkeyCode == 46)||(strkeyCod e==8 ) || (strkeyCode ==9 ) ||
    (strkeyCode==39 ) || (strkeyCode ==35) || (strkeyCode ==36) ||
    (strkeyCode==9) ){}
    else{return false;} }
    return true;}
    function valFuncReg_Mone y(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(tex t));
    if(res==null){
    reg =/^\$?[0-9]+$/;
    regex = new RegExp(reg);
    res= (regex.exec(tex t));}
    return (res != null && value == res[0]);}
    </script>


    The above script can be called on "Onkeypress " event of the TextBox as
    follows :

    "Onkeypress ", "javascript:ret urn checkNumber(thi s,event);"


    Please feel free to give Comments and Suggessions and Bugs also :-)





  • Thomas 'PointedEars' Lahn

    #2
    Re: JavaScript to Validate the Money Field :-)

    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:ret urn checkNumber(thi s,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>

    Comment

    Working...