![](/img/trans.png)
[英]How to encode regex pattern for valid json and html5 for form validation?
[英]Legitimate regex for HTML5 form field validation
是以下正则表达式:
/\\b(http|https|ftp):\\/\\/([-A-Z0-9.]+)(\\/[-A-Z0-9+&@#\\/%=~_|!:,.;]*)?(\\?[A-Z0-9+&@#\\/%=~_|!:,.;]*)?/i
/\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[AZ]{2,6}\\b/i
:[ /\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[AZ]{2,6}\\b/i
我在输入中使用它们,例如:
<section id='email-txt' class='flex-column'>
<label id='address' for='emailTxt'>Address</label>
<input id=emailTxt
type='email'
value='{{webContact.homeEmail}}'
pattern=/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\b/i>
</section>
<section id='col2' class='flex-column'>
<label id='type' for='webPageUrl'>Type</label>
<input id=webPageUrl
type='url'
value='{{webContact.homeEmail}}'
placeholder='http://microsoft.com'
required
pattern=/\b(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i>
</section>
形式,但验证始终不正确。
谢谢
边界\\b
一词与您的情况无关。 如果您进行输入字段验证,请尝试使用^
和$
表达式:
网址:
/^(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?$/i
电子邮件:
/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.