Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- using Nethereum.Util;
- namespace SupplyChain.BlockChain.Validation
- {
- /// <inheritdoc cref="IAddressValidator"/>
- public class AddressValidator : IAddressValidator
- {
- private static readonly Regex AddressRegex = new Regex("^0[xX]([A-Fa-f0-9]{40})$");
- private static readonly AddressUtil AddressUtil = new AddressUtil();
- /// <inheritdoc cref="IAddressValidator.IsValid(string)"/>
- public bool IsValid(string address)
- {
- // Doesn't match length, prefix and hex
- if (!AddressRegex.IsMatch(address))
- {
- return false;
- }
- // It's all lowercase, so no checksum needed
- if (address == address.ToLower())
- {
- return true;
- }
- // Do checksum
- return AddressUtil.IsChecksumAddress(address);
- }
- }
- }
Add Comment
Please, Sign In to add comment