-
Notifications
You must be signed in to change notification settings - Fork 24
Validators
Chris Wood edited this page Oct 3, 2019
·
3 revisions
Validators
var template = "Name: { Name : Contains('B') }";
var input = "Name: Alice, Name: Bob";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("Bob", result.First("Name"));
var template = "Email: { AdminEmail : EndsWith('admin.com') }";
var input = "Email: [email protected] Email: [email protected]";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("[email protected]", result.First("AdminEmail"));
var template = "Date: { Date : IsDateTime('yyyy-MM-dd') }";
var input = "Date: 3rd Oct 2019 Date: 2019-10-04";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("2019-10-04", result.First("Date"));
var template = "Web: { Domain : IsDomainName }";
var input = "Web: n/a Web: www.flipbit.co.uk";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("www.flipbit.co.uk", result.First("Domain"));
var template = "Email: { Email : IsEmail }";
var input = "Email: webmaster at host.com Email: [email protected]";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("[email protected]", result.First("Email"));
var template = "Middle Name: { MiddleName : IsNotEmpty }";
var input = "Middle Name: Middle Name: Charles";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("Charles", result.First("MiddleName"));
var template = "Address: { Address : IsNot('N/A') }";
var input = "Address: N/A Address: 10 Acacia Avenue";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("10 Acacia Avenue", result.First("Address"));
var template = "Age: { Age : IsNumeric }";
var input = "Age: Ten Age: 10";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("10", result.First("Age"));
var template = "Phone: { Phone : IsPhoneNumber }";
var input = "Phone: Disconnected Phone: +44 (0) 1603 555-1234";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("+44 (0) 1603 555-1234", result.First("Phone"));
var template = "Server: { ServerUrl : IsUrl }";
var input = "Server: 192.168.1.1 Server: www.server.com";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("www.server.com", result.First("ServerUrl"));
var template = "Zip: { ZipCode : MaxLength(5) }";
var input = "Zip: 123456 Zip: 78912";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("78912", result.First("ZipCode"));
var template = "Zip: { ZipCode : MinLength(5) }";
var input = "Zip: 123 Zip: 45678";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("45678", result.First("ZipCode"));
var template = "Ip: { InternalIpAddress : StartsWith('192') }";
var input = "Ip: 80.34.123.45 Ip: 192.168.1.1";
var result = new Tokenizer().Tokenize(template, input);
Assert.AreEqual("192.168.1.1", result.First("InternalIpAddress"));