Regular Expression Validator12yAsked Jul 23, 2014, 4:48 AM EDTSolvedShareLinkedInXCopy linkSaveHi All, I have need Regular expression for validation Like /az-Az/ means before and after word , should be forward slash. Thanks,Shiwendra
Regular Expression Validator12yAsked Jul 23, 2014, 4:48 AM EDTSolvedShareLinkedInXCopy linkSaveHi All, I have need Regular expression for validation Like /az-Az/ means before and after word , should be forward slash. Thanks,Shiwendra
VulpesRank #55 · 29.2K reputation12y agoPosted Jul 25, 2014, 6:45 AM EDT✓ Accepted answer0Try this:using System;using System.Text.RegularExpressions;class Program{ static void Main() { string[] names = {"/John/", "/John Doe/", "/John-Doe/", "/John_Doe/","/John Doe's/", "/John Frederick Doe/", "/John Doe 2/", "//John", "/John /", "/John>Doe/"}; string regExp = @"^/\w+((\s+|-|')\w+)*/$"; foreach(string name in names) { Console.WriteLine("{0} -> {1}", name, Regex.IsMatch(name, regExp)); } Console.ReadKey(); }}The output is:/John/ -> True/John Doe/ -> True/John-Doe/ -> True/John_Doe/ -> True/John Doe's/ -> True/John Frederick Doe/ -> True/John Doe 2/ -> True//John -> False/John / -> False/John>Doe/ -> False0Khan Abrar AhmedRank #778 · 3K reputation12y agoPosted Jul 23, 2014, 8:05 AM EDT0Hi try this/[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)/0VulpesRank #55 · 29.2K reputation12y agoPosted Jul 23, 2014, 8:13 AM EDT0The following regular expression will validate text consisting of a single alphabetic word enclosed within forward slashes:string regExp1 = "^/[a-zA-Z]+/$";and this one will do the same thing except that a word can also now include digits and the underscore character:string regExp2 = @"^/\w+/$";The corresponding expressions for multiple consecutive words would be:string regExp3 = "^(/[a-zA-Z]+)+/$";string regExp4 = @"^(/\w+)+/$";0?12y agoPosted Jul 25, 2014, 5:33 AM EDT0/[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)/it work for /John/ but does not work for /John Doe/. so please help for both scenario. Thanks,0?12y agoPosted Jul 27, 2014, 11:15 PM EDT0Hi,Thanks , it work for rme0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khan Abrar AhmedRank #778 · 3K reputation12y agoPosted Jul 23, 2014, 8:05 AM EDT0Hi try this/[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)/0
VulpesRank #55 · 29.2K reputation12y agoPosted Jul 23, 2014, 8:13 AM EDT0The following regular expression will validate text consisting of a single alphabetic word enclosed within forward slashes:string regExp1 = "^/[a-zA-Z]+/$";and this one will do the same thing except that a word can also now include digits and the underscore character:string regExp2 = @"^/\w+/$";The corresponding expressions for multiple consecutive words would be:string regExp3 = "^(/[a-zA-Z]+)+/$";string regExp4 = @"^(/\w+)+/$";0
?12y agoPosted Jul 25, 2014, 5:33 AM EDT0/[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)/it work for /John/ but does not work for /John Doe/. so please help for both scenario. Thanks,0
VulpesRank #55 · 29.2K reputationPosted Jul 25, 2014, 6:45 AM EDT
The output is:
Khan Abrar AhmedRank #778 · 3K reputationPosted Jul 23, 2014, 8:05 AM EDT
/[a-zA-Z]+(([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)/
VulpesRank #55 · 29.2K reputationPosted Jul 23, 2014, 8:13 AM EDT
string regExp1 = "^/[a-zA-Z]+/$";
and this one will do the same thing except that a word can also now include digits and the underscore character:
string regExp2 = @"^/\w+/$";
The corresponding expressions for multiple consecutive words would be:
string regExp3 = "^(/[a-zA-Z]+)+/$";
string regExp4 = @"^(/\w+)+/$";
Posted Jul 25, 2014, 5:33 AM EDT
it work for /John/ but does not work for /John Doe/. so please help for both scenario. Thanks,
Posted Jul 27, 2014, 11:15 PM EDT
Thanks , it work for rme
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts