如何使用jquery从字符串中删除特殊字符? [英] How to remove special characters from string using jquery?

查看:736
本文介绍了如何使用jquery从字符串中删除特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个textarea输入我的名字和地址。但是当我们在character之间放置空格时它也会保存特殊字符。我不想将这些特殊字符保存在数据库中。但是当页面加载时,数据应该带有空格。我们怎么做呢?我尝试使用正则表达式。但问题是,在页面加载之后,数据没有空间和alll.Help我

Hi,

I have one textarea to enter my name and address.But it will save special characters also when we put space between character.I dont want to save these special character in database.But when the page loads,the data should come with spaces.How we can do that?I tried with regular expression.But the problem is that,after pageloading,the data comes without space and alll.Help me

推荐答案

Hello Krishna,



首先,你需要指明你的意思'特殊字符'在不同的场景中可以有所不同。至少,你应该提供一些例子和你想要的输出。



但是,通过一点猜测,我认为你试图拥有像'你的领域中有\[/#
Hello Krishna,

To begin with, you need to specify what you mean by 'special characters' which can be different in different scenarios. At the very least, you should provide some examples and your desired output.

But, with a little bit of guessing, I think you are trying to have characters like '"\][/#


@


^!@。如果是这种情况,尽管使用JQuery很有可能你没有这样做的原因很简单,任何有一点知识的人都可以很容易地绕过它,你的网站很容易被黑客攻击。你要找的是'HTML编码/解码'。看一看在下面的链接/方法。



Server.HTMLEncode方法 [ ^ ]

C#HtmlEncode,HtmlDecode [ ^ ]

HttpServerUtility.HtmlEncode方法(字符串) [ ^ ]



希望这会有所帮助,干杯
^!@ in your field. If this is the case, whilst this is quite possible using JQuery, you don't do that for the simple reason, anyone with a little bit of knowledge can bypass that very easily and your website will be hacked quite easily. What you are looking for is called 'HTML Encoding/Decoding'. Take a look at the below links/methods.

Server.HTMLEncode Method[^]
C# HtmlEncode, HtmlDecode[^]
HttpServerUtility.HtmlEncode Method (String)[^]

Hope this helps, Cheers


这篇关于如何使用jquery从字符串中删除特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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