0

I like to make a client-side validation with JavaScript. For this I'm using the jQuery Plugin Validate() watch here: http://docs.jquery.com/Plugins/Validation/Methods

By clicking on the submit Button I want to compare the ID inside the iput field with an regular expression. How can I solve this?

For now I did it like this:

<form id="checkoutFormBean" action="/view/checkout?execution=e3s1" method="POST">
    <li>
    <input id="id" name="id" class="fieldError required number" tabindex="12" value="" maxlength="2048" type="text">
    </li> 


    <script type="text/javascript">
            $(document).ready(function(){
                $("#checkoutFormBean").validate({
                    id: "required",
                    id: {
                        equalTo: "/^2099[0-9]{9}$/"
                    }
                });
            });

        </script>

But its not working

1
  • You can't have two properties named 'id' in the same object literal. The second one probably just replaces the first. Commented Apr 13, 2012 at 7:08

1 Answer 1

1

After submiting, you just need to use rules to validate.Please have a look into the following url.Here you will get an idea how to specify the rules.

For Example:

$("#checkoutFormBean").validate({
   rules: {
     name: {
       required: true,
       equalTo: "/^2099[0-9]{9}$/"
     }
   }
});

Hope this helps you :-)

Sign up to request clarification or add additional context in comments.

2 Comments

I just checked it with an right value like 2099123456789 but it says that it's an wrong value !? any hint?
May be try to mention this and check pattern-match: true. If its not working please find this url for custom rules: peterotten.com/custom-jquery-validation-rules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.