Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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

Revisions

  1. jimmiw created this gist Feb 9, 2010.
    14 changes: 14 additions & 0 deletions simple prototype form validation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Event.observe('submit_button','click', function(e) {
    e.stop();

    var contact = $('form_name').getValue();
    var comment = $('form_comment').getValue();
    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();
    }
    }
    });