Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help validating multi form

    ##Background##
    i am a complete noob with JS (i can slightly read it, but cant write it)

    ##Problem##
    Link: http://s328792954.websitehome.co.uk//multi_step_form/

    Im trying to make a multi-step form,
    and i cam across a tutorial on-line which showed a basic example.

    anyway.....

    i've added a field for number only (loan amount)
    but the coding i use is obviously wrong because now it will not accept any form of input



    Code:
    var fields = $('#first_step input[type=amountborrow]');
      var  numericExpression = /^[0-9]$/;
            var error = 0;
            fields.each(function(){
                var value = $(this).val();
                if( value.length<3 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='amountborrow' && !numericExpression.test(value) ) ) {
                    $(this).addClass('error');
                    $(this).effect("shake", { times:3 }, 50);
                    
                    error++;
                } else {
                    $(this).addClass('valid');
                }
            });
    please help (sorry if this is wrong section i didnt really understand forum sections)

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Your regexp is wrong:
    Code:
    var numericExpression = /^[0-9]$/;
    It tests for only one single digit. Since you enforce a minimum length of 3, this is never true.

    If you want to test that there are only digits in there, no matter how many, use this:
    Code:
    var numericExpression = /^\d*$/;
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •