验证在ASP.NET查询字符串 [英] Validate QueryStrings in ASP.NET

查看:192
本文介绍了验证在ASP.NET查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个图书馆在那里,我可以在我目前的ASP.NET应用程序使用,以验证查询字符串?

Is there a library out there which I can use in my current ASP.NET app, to validate queryStrings?

编辑〜使用正则表达式查找模式,如字符串,只有,只有数字,字符串长x ...等

Edit ~ Using Regex to look for patterns, like string, only, numeric only, string with length x,...etc

感谢

推荐答案

不知道有一个图书馆,但如果查询字符串存在,你可以用它来检查:

Don't know about a library, but you can use to check if the querystring exists:

if (!String.IsNullOrEmpty(Request.Querystring["foo"]))
{
   // check further
}
else
{
   // not there, do something else
}

如果你想使用Reglar防爆pressions进一步验证,您可以创建一个接受的字符串类,并返回一个布尔值。

If you want to use Reglar Expressions to further validate, you can create a class that accepts the string and return a boolean.

public static Boolean IsValid(String s)
{
    const String sRegEx = @"regex here";

    Regex oRegEx = new Regex(sRegEx , RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
    MatchCollection oMatches = oRegEx.Matches(s);

    return (oMatches.Count > 0) ? true : false;
}

这是一个很好的免费计划,以帮助您构建regluar前pressions:防爆preSSO

This is a good free program to help you build the regluar expressions: Expresso

这篇关于验证在ASP.NET查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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