How to specify a custom error message in Bootstrap for input fields

I am using Twitter-Bootstrap in .NET 4.0. I do not use additional jQuery validation plugins.

I have this code:

<asp:TextBox ID="Url" runat="server" required Text='' placeholder="enter the URL" pattern="http://*" messages="Must start with 'http://' or 'https://' "></asp:TextBox> 

Regex validation works if I type 'asdf' into:

enter image description here

My question is: how do I configure the error "Please agree to the requested format" to say "Must start with" http: // "or" https: // "?

As you can see, I tried "messages =". I also tried several others.

  • How to set up a general error message?
  • Is there any documentation for Bootstrap that has more info on this?
+6
source share
2 answers

This actually has nothing to do with the download, rather it is an implementation of HTML html5 form input validation in your browser (Chrome, by the look of your screenshot).

When using the pattern attribute, you must use title to provide additional assistance to the user ( see MDN docs ).

With title="Must start with 'http://' or 'https://'" you should see something like this (in Chrome, different browsers will look different):

Validating input using template and header attributes http://junkheap.thirdraven.com/input_with_pattern_and_title_set.png

You can also try changing the input type to a URL, which will give you a different message even without a header, but my own experience was that sometimes a validation checked by the browser can be a little frustrating.

+10
source

If you want to modify an invalid message, you can use the oninvalid attribute.

oninvalid="this.setCustomValidity('User ID is a must')"

Hope this helps you.

+5
source

All Articles