Skip to content

Instantly share code, notes, and snippets.

@jimmiw
Created February 9, 2010 09:58
Show Gist options
  • Select an option

  • Save jimmiw/299064 to your computer and use it in GitHub Desktop.

Select an option

Save jimmiw/299064 to your computer and use it in GitHub Desktop.

Revisions

  1. jimmiw revised this gist Feb 9, 2010. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions simple jquery form validation
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    $('#contact_form').bind('submit', function(e) {
    return false;
    });

    $('#submit_button').bind('click',function(e) {
    e.stopPropagation();

    @@ -8,6 +12,7 @@ $('#submit_button').bind('click',function(e) {
    var emailRegExp = new RegExp('^[a-zA-Z0-9._+-]+[@]{1}[a-zA-Z0-9._-]+[.]{1}[a-zA-Z0-9]+$');

    if(phoneRegExp.test(contact) || emailRegExp.test(contact)) {
    $('#contact_form').unbind();
    $('#contact_form').submit();
    }
    }
  2. jimmiw created this gist Feb 9, 2010.
    14 changes: 14 additions & 0 deletions simple jquery form validation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    $('#submit_button').bind('click',function(e) {
    e.stopPropagation();

    var contact = $('#form_name').val();
    var comment = $('#form_comment').val();
    if(contact != '') {
    var phoneRegExp = new RegExp('^[+]{0,1}[0-9]+$');
    var emailRegExp = new RegExp('^[a-zA-Z0-9._+-]+[@]{1}[a-zA-Z0-9._-]+[.]{1}[a-zA-Z0-9]+$');

    if(phoneRegExp.test(contact) || emailRegExp.test(contact)) {
    $('#contact_form').submit();
    }
    }
    });