zoukankan      html  css  js  c++  java
  • PetShop文本输入过滤函数

    /// <summary>
            
    /// Method to make sure that user's inputs are not malicious
            
    /// </summary>
            
    /// <param name="text">User's Input</param>
            
    /// <param name="maxLength">Maximum length of input</param>
            
    /// <returns>The cleaned up version of the input</returns>

            public static string InputText(string text, int maxLength)
            
    {
                text 
    = text.Trim();
                
    if (string.IsNullOrEmpty(text))
                    
    return string.Empty;
                
    if (text.Length > maxLength)
                    text 
    = text.Substring(0, maxLength);
                text 
    = Regex.Replace(text, "[\\s]{2,}"" ");    //two or more spaces
                text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)""\n");    //<br>
                text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+"" ");    //&nbsp;
                text = Regex.Replace(text, "<(.|\\n)*?>"string.Empty);    //any other tags
                text = text.Replace("'""''");
                
    return text;
            }
  • 相关阅读:
    vscode设置js文件自动格式化单引号
    解决git每次输入账号密码问题
    vscode设置vouter标签不换行
    查看修改npm地址并登录
    正则匹配[]外部的内容
    使用v-model实现父子组件之间传值
    发布网站
    安装IIS
    IIS服务添加角色
    react生命周期
  • 原文地址:https://www.cnblogs.com/wuliang/p/982333.html
Copyright © 2011-2022 走看看