📄 tools.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
namespace Registration
{
class Tools
{
/// <summary>
/// this function strips non-numeric values out of a string and returns the numeric content of a string.
/// </summary>
/// <param name="Value"></param>
/// <returns></returns>
public static string StripNonNumeric(string Value)
{
if (Value == null) return "";
return Regex.Replace(Value, "\\D", "");
}
public static string StripString(string targetString)
{
if (targetString == null) return "";
return Regex.Replace(targetString, @"\W*", "");
}
public static NameValueCollection GetValues(string sNVPairs)
{
String[] sbNameValuePair;
String[] sbNameValuePairs;
NameValueCollection m_colNVPairs = new NameValueCollection();
//split into name-value pairs: "name=value"
sbNameValuePairs = sNVPairs.Split('&');
for (int i = 0; i < sbNameValuePairs.Length; i++)
{
//split the name value pair: var1=name, var2=value
sbNameValuePair = sbNameValuePairs[i].Split('=');
//decode the values and add the pair to a collection
m_colNVPairs.Add(System.Web.HttpUtility.UrlDecode(sbNameValuePair[0]),
System.Web.HttpUtility.UrlDecode(sbNameValuePair[1]));
}
return m_colNVPairs;
}
public static bool ValidNRIC(string ic)
{
string icStr = ic.ToUpper().Trim();
string regexPattern = "S[0-9]{7}[A-Z]";
if(icStr.Length<9)
return false;
if (!Regex.IsMatch(icStr.ToUpper(), regexPattern))
return false;
int[] weight = new int[] { 0, 2, 7, 6, 5, 4, 3, 2 };
char[] checkDigits = new char[] { 'J', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Z', 'J' };
int sum = 0;
try
{
for (int i = 1; i < 8; i++)
{
sum += int.Parse(icStr[i].ToString()) * weight[i];
}
sum = sum % 11;
sum = 11 - sum;
return (icStr[8]==checkDigits[sum]);
}
catch { return false; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -