Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2011, 09:19 PM   PM User | #1
Wednesdai
New to the CF scene

 
Join Date: Apr 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Wednesdai is an unknown quantity at this point
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)
Wednesdai is offline   Reply With Quote
Old 10-19-2011, 12:15 PM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
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
venegal is offline   Reply With Quote
Reply

Bookmarks

Tags
validation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:52 PM.


Advertisement
Log in to turn off these ads.