two functions with same trigger

two functions with same trigger

Hi Guys!

I've got a small problem with my webform. One function is validating my form and the other sends it via ajax to a php file where all the mysql stuff is executed.

Both functions use submit as a trigger and the submit function should only be called if the validation is successfull. I read stuff about callbacks and preventDefault but I don't get it runnin'.

  1. $(document).ready(function(){
  2.     $("#inputInfos").submit(function(){   
  3.     // formvalidation
  4.     });
  5. });
  6. $(document).ready(function(){
  7.     $("#inputInfos").submit(function(){   
  8.     // ajax form submit
  9.     });
  10. });

And because I'm a regex beginner too, here another question. In my validation class I check three diffrent types of input fields. Most of all is working, but please check if there are possible improvements on my code (and I bet there are!), thanks.
  1. only numbers, min 1 and max 20 characters long, no dots, commas, whatever --> WORKS
  2. if (!/^([\d]{1,20})$/.test(input.val())) {

  3. a select box with default value "select object", value != default value --> WORKS
  4. if (!/^[^select].*$/.test(charclass.val())) {

  5. the tricky one... only space(s), numbers and alphabetic characters only, no space at start or in the end (doesn't work), no double spaces, 3-20 chars.
  6. if (!/^[^ ](?!.*[ ]{2})([a-zA-Z0-9 ]{3,20})/.test(name.val())) {

Greetings Fabio