我们如何更新validation.js(javascript)以防止将非ASCII字符提交到数据库的文本字段? [英] How we Update validation.js(javascript) to prevent non ascii characters from being submitted to the database for text fields?

查看:114
本文介绍了我们如何更新validation.js(javascript)以防止将非ASCII字符提交到数据库的文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何更新validation.js(javascript)以防止将非ASCII字符提交给文本字段的数据库?

How we Update validation.js(javascript) to prevent non ascii characters from being submitted to the database for text fields?

推荐答案

您不需要验证吗对此.您可以从输入中过滤掉我们不需要的字符.您确实需要使用Javascript来执行此操作,因为您要处理的事件过于频繁.您可以将其与验证结合起来,以便更好地在服务器端执行.

查看此代码示例,该代码示例使您可以过滤除数字和``.''之外的所有内容:
You do not need validation do to that. You can filter our unwanted characters from input. You really need to do it in Javascript as the event you''re going to process is too frequent. You can combine this with validation which you better perform on the server side.

Look at this code sample which enables you to filter out everything except digits and ''.'':
<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>



请注意,也应允许将退格键(#8)作为字符处理.
使用此方法可以传递所需的字符代码点范围.

祝你好运,

—SA



Pay attention that backspace (#8) is also should be allowed as it is processed as a character.
Use this idea to pass the range of character code point you need.

Good luck,

—SA


这篇关于我们如何更新validation.js(javascript)以防止将非ASCII字符提交到数据库的文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆