Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate pattern matching in textarea?

Tags:

html

textarea

When I use textarea.checkValidity() or textarea.validity.valid in javascript with an invalid value both of those always return true, what am I doing wrong?

<textarea name="test" pattern="[a-z]{1,30}(,[a-z]{1,30})*" id="test"></textarea>​  jQuery('#test').on('keyup', function() {     jQuery(this).parent().append('<p>' + this.checkValidity() + ' ' +     this.validity.patternMismatch + '</p>'); }); 

http://jsfiddle.net/Riesling/jbtRU/9/

like image 521
Riesling Avatar asked Nov 30 '12 10:11

Riesling


People also ask

Can we use pattern in textarea?

HTML5 <textarea> element does not support the pattern attribute.

How validate textarea in PHP?

If you use prepare statements then you will not need real_escape_string at all. For validating ANY field you need to consider what it is allowed to contain and either remove anything that is invalid or reject the field if it contains anything invalid. it is not working.

Can we use value attribute in textarea?

From the MDN documentation: " <textarea> does not support the value attribute".

How do you validate a name field in HTML?

The validation process evaluates whether the input value is in the correct format before submitting it. For example, if we have an input field for an email address, the value must certainly contain a valid email address; it should start with a letter or a number, followed by the @ symbol, then end with a domain name.


1 Answers

HTML5 <textarea> element does not support the pattern attribute.

See the MDN doc for allowed <textarea> attributes.

You may need to define this functionality yourself.

Or follow the traditional HTML 4 practice of defining a JavaScript/jQuery function to do this.

like image 106
Dipesh Shah Avatar answered Sep 19 '22 15:09

Dipesh Shah