javascript - Define allowed characters in text objects HTML -


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

'' . No warning. - You can extend this concept independently to include in your code (the way your code-flow fits) (and where it is needed, give it to input type = "text"

Edit:
Note that your current is valid - category specifications ( \ u0000- \ u00FF ) are all special types of 'Pesky' Effectively reject special characters:

  • Fancy quote '' ""
  • € However, it is perfectly well done with full C1 control.
  • -Block (), on the other hand .. It is in line with the inclusion of the complete C-control block. Effectively, it is now valid for your (which you have requested) valid four-set:

    As you can see now, this is too much for this reason that sensible applications (ultimately) Unicode (usually encoded for the web in the form of UTF-8) Yoga is starting to begin and the users who provide (only (obviously clearly) reasons to accept)
    Most Common Verification Question (Real World To validate the concept is nothing more than the example of high-school-class (and even more: regularly with examples that can be easily understood to explain the basics Name of the expression, such as name / email / Address) apply some official identification system (passport etc.) for the regrettable that people's names, addresses etc. In fact: Even the absolute current Unicode names each person (in original writing) on ​​the planet (that's actually still alive) !! Real world example: When your boarding pass has different certificates, try leaving the commercial flight and leaving it, then your passport (whatever is wrong). 'Just' missing an umlaut is a problem, somewhere bad situation, imagine a woman with a German name, Thai married a man with last name and a masculine last name ..

    End: Please feel that Most of the cases This is completely useless (if you silently do without any warning) because:
    You never can simply accept user input on the server - without proper cleaning In the party , so you are already cleaning your input on that form (without knowing the user) on a form that you forget to think of users with a newbie programmer (Javascript (For example), it sometimes seems to repeat the work done in Javascript already on the client-side) ... Typically , replicating th Server-side vendor on client-side (Usually using Javascript), the user dynamically knows how the server will not be allowed (by sending the data back and forth) and accordingly customize it!


Comments