Anyway, can I define encoding in text areas using HTML and Pure JS?
I do not want them to allow special Unicode characters (like ♣ ♦ ♠).
Valid character range (for my purpose) Unicode code point U + 0000
to U + 00FF
.
It is okay to transfer accurate words with empty string on form submissions (without warning to user).
So, as you have explained in your comments: you want to replace those characters, Who regardless of the warning on form-submission with invalid string invalid.
The following example html (body content):
& lt; Form action = "demo_form.asp" & gt; First name: & lt; Input type = "text" name = "fname" /> & Lt; Br> Last name: & lt; Input type = "text" name = "lname" /> & Lt; Br> Likes: & lt; Textarea name = "txt_a" & gt; & Lt; / Textarea & gt; & Lt; Br> What she Dislikes: & lt; Textarea name = "txt_b" & gt; & Lt; / Textarea & gt; & Lt; Br> & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt;
Here is a basic concept javascript:
function demo () {for (var elms = this.getElementsByTagName ('textarea'), l = ams .length; L -; Elmas [L] .value = elms [L] .value.replace (/ [^ \ u0000- \ u00FF] / g, '')); } Window.onload = function () {document.forms [0] .onubmit = Demo; // Use any method of choice on the onsubmit of the hook form;
The basic idea is to emphasize the browser's Regex engine to match on Unicode (local charset) using \ uXXXX
notation.
Then we only limit one: [\ u0000- \ u00FF]
and finally we specify that <^> [^ \ u0000- \ U00FF] .
All the items that match those criteria will be replaced with form code (submission) on
Comments
Post a Comment