Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- namespace WindowsFormsApp1.Services.RegexAnalyse
- {
- class RegexAnalyseService : IRegexAnalyseService
- {
- public string OnlyPositiveDigitNumbers(string number)
- {
- string pattern = @"^[0-9]([.,][0-9]{1,3})?$";
- //string pattern = @"^[1-9]\d{0,4}$";
- var regex = new Regex(pattern);
- bool match = regex.IsMatch(number);
- if (!match && !string.IsNullOrEmpty(number))
- {
- number = number.Remove(number.Length - 1);
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment