jQuery公式验证

i have an ajax form like this:

$(function() {
  $('.send').click(function(e) {
    $.ajax({
      url: 'email.php',
      type: 'POST',
      data: {
        'message': $('.inner').html(),
        'email':   $('[name="email"]').val(),
        'name':    $('[name="name"]').val(),
        'preis':   $('.overallprice').html()    
      },
      success: function(data) {
        alert('Ihre Daten wurden erfolgreich gesendet');
      }
    });
  });
});

I want the script to check if someone filled the form correctly (name & mail). Tried to use .checkValidity() but i couldnt get it to work.

you can use jquery validation here an example

You should use the Jquery validation plugin (http://jqueryvalidation.org/), which is really powerful. Most of the base stuff is already done and one of the most important aspects for validation tasks, it is tested!

You can simply define rules like:

 rules: {
        address: "required",
        postal_code: {
            required: true,
            minlength: 5,
            maxlength: 5,
            digits: true
        },
        locality: "required",
        house_number_1: {
            number: true,
            required: true
        },

And an awesome feature is that you can simply extend it like

house_number_2: {
           mySelfDefinedRule: true
        },

And the Rule could be defined this way:

$j.validator.addMethod("mySelfDefinedRule", function (value, element) {
    if ($j("#input_traffic_houseNumber2").val() === "") {
        return true;
    } else {
        return parseInt($j("#input_traffic_houseNumber1").val()) <= parseInt(value);
    }

}, 'Must be greater then HouseNumber One');

The code above is just an easy/ simplified example which shows you how to use. Hope that helps you!