[英]Legitimate regex for HTML5 form field validation
Is the following regex: 是以下正则表达式:
/\\b(http|https|ftp):\\/\\/([-A-Z0-9.]+)(\\/[-A-Z0-9+&@#\\/%=~_|!:,.;]*)?(\\?[A-Z0-9+&@#\\/%=~_|!:,.;]*)?/i
网址: /\\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
:[ /\\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\\.)+[AZ]{2,6}\\b/i
I am using them in inputs like: 我在输入中使用它们,例如:
<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>
in forms but the validation is always incorrect. 形式,但验证始终不正确。
Thanks 谢谢
The word boundaries \\b
are not pertinent in your case. 边界\\b
一词与您的情况无关。 If you do input fields validation, try those regexes with ^
and $
: 如果您进行输入字段验证,请尝试使用^
和$
表达式:
url: 网址:
/^(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?$/i
email: 电子邮件:
/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.