Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
is there anyway to not allow users to type unicode characters for the name, last name, address of a user that is either in canada or USA. Please note than canada users can use French characters as well.
Thanks
Posted
Updated 20-Jun-11 5:36am
v2

1 solution

Not using Unicode won't help you. (Also, there is not such thing as non-Unicode characters, but you probably need code point subset, something like ASCII, also may be not exactly what you need.) Decide what exactly You can filter out some characters.

Here is one code sample:
HTML
<html>
   <head>
      <script type="text/javascript"><!--
         function filterDigits(eventInstance) { 
            eventInstance = eventInstance || window.event;
                key = eventInstance.keyCode || eventInstance.which;
            if ((47 < key) && (key < 58) || key = 45 || key == 8) {
               return true;
            } else {
               if (eventInstance.preventDefault)
                  eventInstance.preventDefault();
               eventInstance.returnValue = false;
               return false;
            } //if
         } //filterDigits
      --></script>
   </head>
<body">

<input type="text" onkeypress="filterDigits(event)"/>

</body>
</html>


Pay attention: you also need to allow key code 8 (backspace).

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900