Xml 如何向Odoo中的字段添加验证?

Xml 如何向Odoo中的字段添加验证?,xml,validation,view,field,odoo,Xml,Validation,View,Field,Odoo,我必须在Odoo的注册表单中添加验证(这是auth_注册模块中的auth_signup\u login_templates.xml文件)。我需要确保Name包含在字母表中,并且在3到15个字符之内。现在,默认情况下,名称的代码是: <div class="form-group field-name"> <label for="name" class="control-label">Your Name</label>

我必须在Odoo的注册表单中添加验证(这是auth_注册模块中的
auth_signup\u login_templates.xml
文件)。我需要确保
Name
包含在字母表中,并且在3到15个字符之内。现在,默认情况下,名称的代码是:

         <div class="form-group field-name">
            <label for="name" class="control-label">Your Name</label>
            <input type="text" name="name" t-att-value="name" id="name" class="form-control" placeholder="e.g. John Doe"
                required="required" t-att-readonly="'readonly' if only_passwords else None"
                t-att-autofocus="'autofocus' if login and not only_passwords else None" />
        </div>

你的名字

可以找到xml页面

以进行验证,我们更喜欢Javascript/Jquery:) 例如:

但对于最小和最大长度,可以使用数据属性。 例如:



噢。美好的我使用的html模式也很好,并且需要更少的代码行。但是,这似乎也很好。谢谢。@MinggLex好的,那么你可以接受并投票支持我的答案,这也会帮助其他人。
$('#name').keypress(function (e) {
    var regex = new RegExp(/^[a-zA-Z\s]+$/);
    var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
    if (regex.test(str)) {
        return true;
    }
    else {
        e.preventDefault();
        return false;
    }
});
<input data-rule-minlength="3" data-rule-maxlength="8" data-msg-minlength="Exactly 3 characters please" data-msg-maxlength="Exactly 8 characters please">