0

So I love using the html5 pattern api. I want to setup a pattern(regex) that will not allow html tags to be entered into the form. I have a working example of the pattern api below. What regex should I use to stop all html tags?

<form onsubmit="alert('Boom!'); return false;">
    <input type="text" pattern="[0-1]">
    <input type="submit" value="submit">
</form>
9
  • 4
    As a rule of thumb, don't try to stop people submitting things that look like HTML, just treat the data as text (so replace < with &lt;, & with &amp;, and so on when putting the submitted text into an HTML document). Commented Dec 11, 2013 at 1:04
  • Yeah that's a good idea. But I'm aiming for native html5 validation. Commented Dec 11, 2013 at 1:07
  • 1
    so <input type="text" pattern="^[^<>]+$"> works well. Commented Dec 11, 2013 at 1:16
  • 1
    So nobody is allowed to say that 3 > 2? Commented Dec 11, 2013 at 1:16
  • 1
    <g> is an emoticon. 4 / 2 = 2. Commented Dec 11, 2013 at 1:21

1 Answer 1

1

You want to stop any HTML tags? Easy:

</?[a-z][a-z0-9]*[^<>]*>


You can also match specific tags with this regex:

<specific_tag[^>]*>(.*?)</specific_tag>

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.