English 中文(简体)
表格验证
原标题:Form validation

我想验证我的登记表,但每份案文投入都有违约值。 将所有可能的方法与杂草鉴定成泡。 它难以理解如何使用它(一刀切)) 想要做的是,忽视了缺省价值和确认形式。 我的样子认为:

<from id="reg">
<input class="part1 default" type="text" name="fname" id="fname" value="Adınız (First Name)"/>
<input  class="part1 default"  type="text" name="mname"  value="Atanızın adı (Middle name)"/>
</form>

采用这一代法

var defaultValues = {
     fname :  Adınız ,
     mname :  Atanızın adı ,
     lname :  Soyadınız ,
     phone :  Telefon ,
     email :  Email ,
     pwd : Şifrə ,
     region : Rayon ,
     school : Məktəb ,
     login : Istifadəçi adı ,
     class : Sinif ,
     subject : Fənnin adını daxil edin ,
     dob :  Date of Birth 
};
$( input ).live( focus , function() {
    var el = $(this);
    if (el.hasClass( default )) {
        el.removeClass( default ).val(  );
    }
    if (el.attr( id ) ===  dob ) {
        $(this).mask( 99.99.9999 , {placeholder:   });
    }
});

$( input ).live( blur , function() {
    var el = $(this);
    var name = el.attr( name );

    // Really we only want to do anything if the field is *empty*
    if (el.val().match(/^[s.]*$/)) {

        // To get our default style back, we ll re-add the classname
        el.addClass( default );

        // Unmask the  dob  field
        if (name ==  dob ) {
            el.unmask();
        }

        // And finally repopulate the field with its default value
        el.val(defaultValues[name]);
    }
});

/*validation*/
 $( #reg ).submit(function (event) 
    {
        if ($( #fname ).val() == defaultValues[ Adınız ] || $.trim($( #pwd ).val()) ==   )
        {
            alert( Please enter the name! );
            return false;
        }
        else
        {
            if ($( #fname ).val().length < 2)
            {
                alert( The name must be >2 letters! );
                return false;
            }
        }
    });

你看到的最后一个部分是鉴定。 我对此有如下问题:

  1. Lets say we wrote if s for all possible cases. What if allright and we want to continue submitting process? Do i need to write new if for it and end this if with "return true?"
  2. I used this piece of code but it always gives me the same error message "Please enter a password!" even if all input fields are filled. How can we modify this code to alert the array of errors? for example if my pass is wrong type and name field unfilled the script will show 2 errors at once. I thought about logic too: For example every time when some case is true then it pushes to array the error message and when it finishes checking all cases, shows the error array. But can t realise it. How to validate email field, and date of birth field (looks like "19.16.2010")?
最佳回答

不是将违约价值归入“价值”属性,而是将其定为“转让人”。

<input type="text" name="fname" id="fname" placeholder="Adınız (First Name)"/>

然后,你就能够做正常的鉴定。

问题回答

什么是所有权利,我们希望继续提交进程? 如果是这样的话,我是否需要写新的字句,如果是“真实的吗?”

Yes. return true;

I used this piece of code but it always gives me the same error message "Please enter a password!" even if all input fields are filled. How can we modify this code to alert the array of errors? for example if my pass is wrong type and name field unfilled the script will show 2 errors at once.

你们首先需要收集所有错误,然后用所有错误来显示信息,例如综合数据,像一个阵列。

我也想到逻辑: 举例说,每当某一案件属实时,就会推向错误信息,在完成对所有案件的检查时,就会发现错误阵列。 但这可以实现。 如何验证电子邮件领域和出生地日期(如“19.16.2010”)?

你们需要为每一种类型的数据提供例行验证。 之后,你可以把每个领域的职能称为包含这种数据类型:

form element -> data-type -> validation function

难道你们应该只是利用 j鱼鉴定金来避免 has子吗? 我认为,你不是第一个处理这个问题的人,因此也许值得dig。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签