真爱无限的知识驿站

学习积累技术经验,提升自身能力

[转载]验证正则表达式集合-1

常用表达式:

asp.net 验证正则表达式

整数或者小数:^[0-9]+.{0,1}[0-9]{0,2}$
只能输入数字:"^[0-9]*$"。
只能输入n位的数字:"^d{n}$"。
只能输入至少n位的数字:"^d{n,}$"。
只能输入m~n位的数字:。"^d{m,n}$"
只能输入零和非零开头的数字:"^(0|[1-9][0-9]*)$"。
只能输入有两位小数的正实数:"^[0-9]+(.[0-9]{2})?$"。
只能输入有1~3位小数的正实数:"^[0-9]+(.[0-9]{1,3})?$"。
只能输入非零的正整数:"^+?[1-9][0-9]*$"。
只能输入非零的负整数:"^-[1-9][]0-9"*$。


c#写扩展方法

学习MVC时,学会了写扩展方法,用起来很方便。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
namespace MvcApp1.Content
{
    //<%@ Import Namespace="MvcApp1.Content" %>
    public static class MyHtmlHelper
    {
        public static string RedLable(this HtmlHelper helper, string lbstr)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<span style='color:red;'>");
            sb.Append(lbstr);
            sb.Append("</span>");
            return sb.ToString();
        }
    }
}


<< 1 >>

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号