0

Is the following regex:

  1. url: /\b(http|https|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i
  2. email: /\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{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

3
  • 2
    Try quoting the pattern attribute; just like you would any other attribute. This isn't a dart problem. Commented Dec 15, 2013 at 4:13
  • Your regex reject abc@xyz that is a valid email address, en.wikipedia.org/wiki/Email_address#Valid_email_addresses Commented Dec 15, 2013 at 11:13
  • quoted in single or double quotes - still does not work. Checked the regex with tools and all say its correct. Cannot understand why it does not work. Commented Dec 15, 2013 at 13:43

1 Answer 1

1

The word boundaries \b are not pertinent in your case. 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.