/// <summary>
 /// Converts a string to a valid latin user name.
 /// </summary>
 /// <param name="input">The string to be validated.</param>
 /// <returns>A valid user name.</returns>
 public static string ToValidUsername(this string input)
 {
     input = input.ConvertCyrillicToLatinLetters();
     // You can find more about regular expressions at
     // https://en.wikipedia.org/wiki/Regular_expression
     // or try some examples at http://regexr.com/
     return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
 }
 /// <summary>
 /// Converts string to valid username
 /// </summary>
 /// <param name="input">input string</param>
 /// <returns>string</returns>
 public static string ToValidUsername(this string input)
 {
     input = input.ConvertCyrillicToLatinLetters();
     return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
 }
        /// <summary>
        /// The method validates a string representing username by removing 
        /// unnecessary letters from it.
        /// </summary>
        /// <param name="input">The username string on which the method is called.</param>
        /// <exception cref="System.NullReferenceException"></exception>
        /// <returns>Returns a new string with valid chars only.</returns>
        public static string ToValidUsername(this string input)
        {
            input = input.ConvertCyrillicToLatinLetters();

            // The replace method removes all chars which are not English letters, numbers, underscore or a dot.
            return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
        }
 /// <summary>
 /// Convert given user name as string to valid user name - remove bad characters from the string
 /// </summary>
 /// <param name="input">User name as string value to be validated</param>
 /// <returns>Valid user name as string (removed bad charactes)</returns>
 public static string ToValidUsername(this string input)
 {
     //If the input is not in latin letters, convert it, than
     //remove symbols different than letters, numbers, '_', '\', '.' and all empty spaces
     //than return the result
     input = input.ConvertCyrillicToLatinLetters();
     return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
 }
        /// <summary>
        /// Converts the string input to a valid user name format, cyrilic is replaced by latin.
        /// </summary>       
        public static string ToValidUsername(this string input)
        {
            input = input.ConvertCyrillicToLatinLetters();

            //the expression replaces any invalid character with space
            return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
        }
        /// <summary>
        /// Converts a string to a valid username
        /// </summary>
        /// <param name="input">String to convert</param>
        /// <returns>A string that is a valid username</returns>
        /// <example>
        /// This sample shows call to call the <see cref="ToValidUsername"/> method
        /// <code>
        /// string username = "bai pesho-95".ToValidUsername();
        /// </code>
        /// </example>
        public static string ToValidUsername(this string input)
        {
            input = input.ConvertCyrillicToLatinLetters();

            // remove invalid characters and return converted string
            return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
        }
Example #7
0
        /// <summary>
        /// Returns the given <paramref name="input"/> as <seealso cref="System.String"/> in valid format.
        /// </summary>
        /// <param name="input">The input value, which have to be validated.</param>
        /// <returns>Returns the given <paramref name="input"/>,
        /// excluding it's non-alphabet symbols, except for numbers, lower nyphen and dot!
        /// </returns>
        /// <example>
        /// A simple example of the method logic.
        /// <code>
        /// class TestExtensions
        /// {
        ///     static void Main()
        ///     {
        ///         Console.WriteLine("borisla21321(*67123)".ToValidUsername());
        ///         //output :  borisla2132167123 
        ///     }
        /// }  
        /// </code>
        /// </example>
        public static string ToValidUsername(this string input)
        {
            input = input.ConvertCyrillicToLatinLetters();

            //remove all non-alphabet symbols, excluding numbers, lower hyphen and dot(.)
            return Regex.Replace(input, @"[^a-zA-z0-9_\.]+", string.Empty);
        }