以下是正则表达式:
/\b(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i
/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{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>
表格,但验证总是不正确的。
由于
答案 0 :(得分:1)
单词边界\b
与您的情况无关。如果您输入字段验证,请尝试使用^
和$
的正则表达式:
<强> URL:强>
/^(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?$/i
电子邮件:强>
/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i