Social-security-number matching: [0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9] : Regex SIN « Regular Expression « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;

public class MainClass{

   public static void Main(){
        Regex r1 = new Regex("[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]");
        
        string s = "011-01-0111";
        string s2 = "abc-01-0111";

        
        Console.WriteLine(r1.ToString());
        Console.WriteLine(r1.IsMatch(s)); 
        Console.WriteLine(s2);
        Console.WriteLine(r1.IsMatch(s2));
   }
}
[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]
True
abc-01-0111
False








17.9.Regex SIN
17.9.1.Social-security-number matching: [0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]
17.9.2.Social-security-number matching: [0-9]{3}-[0-9]{2}-[0-9]{4}