如何在ClientValidationFunction中修剪字符串 [英] How to trim string in ClientValidationFunction

查看:105
本文介绍了如何在ClientValidationFunction中修剪字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 CustomValidator ,我需要检查输入字符串的长度。但是在此之前,为了稍微抵消作弊者,我想从字符串中删除所有前导和尾随空格。在这种情况下最简单的方法是什么?

I am writing a client-side validation function for CustomValidator and I need to check length of entered string. But before, to counteract cheaters a little, I want to remove all leading and trailing spaces from the string. What is the easiest way to do it in this scenario?

谢谢!

推荐答案

最简单的方法是在页面上调用ValidatorTrim(value)javascript函数。此函数来自每个asp.net验证器添加到页面时都包含的javascript。

The easiest way is to call the ValidatorTrim(value) javascript function on your page. This function comes from the javascript that every asp.net validator includes when added to a page.

但是我不认为它具有文档功能,因此您不能依靠在以后的验证器版本中可用。因此,我很可能会使用jQuery,或者像J Cooper所指出的那样添加您自己的函数。

But i don't think its a documented feature, so you cant rely on it being available in future versions of the validators. So i would prolly go through jQuery, or add your own function as J Cooper points out.

这篇关于如何在ClientValidationFunction中修剪字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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