在我的表单中,我想使用新的HTML5表单类型,例如<input type="url" />(有关这里类型的更多信息).
The problem is that Chrome wants to be super helpful and validate these elements for me, except that it sucks at it. If it fails the built-in validation, there's no message or indication other than the element getting focus. I prefill URL elements with "http://", and so my own custom validation just treats those values as empty strings, however Chrome rejects that. If I could change its validation rules, that would work …
我有一个简单的表单,需要验证输入的开头和结尾是否不是空格.
在HTML5中,我将这样做:
<input type="text" pattern="^(?!\s|.*\s$).*$">
Run Code Online (Sandbox Code Playgroud)
新Angular 2 ngControl指令中验证模式的正确属性是什么?官方Beta API仍缺乏此问题的文档.
这个小的HTML5密码字段完美地工作,没有oninvalid属性(模式说:最少6个字符):
<form>
<input type="password" name="user_password_new" pattern=".{6,}" required />
<input type="submit" name="register" value="Register" />
</form>
Run Code Online (Sandbox Code Playgroud)
在这里查看jsFiddle .
但是当我添加一个oninvalid属性,当用户的输入不符合模式时会发出自定义错误消息,整个字段永远不会变为有效,请参阅此处的代码:
<form>
<input type="password" name="user_password_new" pattern=".{6,}" oninvalid="setCustomValidity('Minimum length is 6 characters')" required />
<input type="submit" name="register" value="Register" />
</form>
Run Code Online (Sandbox Code Playgroud)
在这里查看jsFiddle .
你能发现错误吗?
我有一个多个复选框的列表.用户可以检查所有,但至少需要.不知道如何实现这一目标
<p>Box Set 1</p>
<ul>
<li><input name="BoxSelect[]" type="checkbox" value="Box 1" required><label>Box 1</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 2" required><label>Box 2</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 3" required><label>Box 3</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 4" required><label>Box 4</label></li>
</ul>
<p>Box Set 2</p>
<ul>
<li><input name="BoxSelect[]" type="checkbox" value="Box 5" required><label>Box 5</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 6" required><label>Box 6</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 7" required><label>Box 7</label></li>
<li><input name="BoxSelect[]" type="checkbox" value="Box 8" required><label>Box 8</label></li>
</ul>
<p>Box Set 3</p>
<ul>
<li><input name="BoxSelect[]" type="checkbox" value="Box 9" required><label>Box 9</label></li>
</ul>
<p>Box …Run Code Online (Sandbox Code Playgroud) 我的表单中有这个输入代码:
<input maxlength="255" id="information_name" name="information[name]" oninvalid="check(this)" placeholder="Nombre Completo" required="required" size="30" style="width:528px;height:25px;" tabindex="3" type="text">
Run Code Online (Sandbox Code Playgroud)
我用这个javascritp代码更改了oninvalid消息:
<script>
function check(input) {
if (input.value == "") {
input.setCustomValidity('Debe completar este campo.');
} else {
input.setCustomValidity('Debe corregir este campo.');
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是问题所在,如果我点击提交并且该字段为空,则该字段显示错误,因此我需要填写该字段,但填写该字段后,即使填充不为空,我仍然会收到警告.
我做错了什么???
如何覆盖symfony2中的表单验证消息.虽然有一个validation.xml文件相关的模型类.我认为它验证了基于html5的表单.
"请匹配请求的格式","请填写此字段".有没有办法覆盖此验证消息.
请帮助我这方面,我被困了一天多,因为我对symfony完全是新手
注意:据我所知,这个问题不是以下问题的重复问题:
给定一个字段:
pattern用于验证的属性集,例如"[a-f,0-9]{4}"用于一个4个字符的十六进制字符串输入。oninvalid设置setCustomValidity('...some message...')为定义自定义验证消息oninput设置setCustomValidity('')为在输入时重置这是一个示例:
/* jshint esnext: true */
const form = document.querySelector("#form");
const field = document.querySelector("#field");
const output = document.querySelector("#output");
form.addEventListener('submit', (e) => {
console.log("SUBMIT");
output.textContent = field.value;
e.preventDefault(); // Prevent default POST request
});
field.oninvalid = (event) => {
console.log("INVALID");
event.target.setCustomValidity('must be valid 4 hex characters');
}
field.oninput = (event) => {
console.log("INPUT"); …Run Code Online (Sandbox Code Playgroud)如果我在 vue 上这样做:
<input pattern="\d+">
Run Code Online (Sandbox Code Playgroud)
它得到了正确的验证,但我收到一个弹出窗口,其中显示一条消息“请匹配请求的格式”。
有什么办法可以改变这个消息吗?我找不到有关接受的验证标签的文档。
JSFiddle: http: //jsfiddle.net/ovz5p3wt/
在symfony 2中,我有一个name我要验证它的文件,如果它包含数字,我想显示一条消息.我的代码是:
//Entity/Product.php
/**
* @ORM\Column(name="`name`", type="string", length=255)
* @Assert\NotBlank()
* @Assert\NotNull()
* @Assert\Regex(pattern="/[0-9]/",match=false,message="Your name cannot contain a number")
*/
protected $name;
Run Code Online (Sandbox Code Playgroud)
但是当我在字段中写一个数字时,我会看到此消息,Please match the requested format因为我的字段代码如下所示:
<input type="text" id="mzm_testbundle_category_name" name="mzm_testbundle_category[name]" required="required" maxlength="255" pattern="((?![0-9]).)*">
Run Code Online (Sandbox Code Playgroud)
输入标签有一个模式和错误,我看到是来自HTML5.我怎样才能解决这个问题呢?