{"id":70366,"date":"2022-05-23T08:00:04","date_gmt":"2022-05-23T06:00:04","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=69629"},"modified":"2022-05-23T08:17:03","modified_gmt":"2022-05-23T06:17:03","slug":"validate-input-regular-expressions-blazor-webassembly","status":"publish","type":"post","link":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/","title":{"rendered":"Validate User Input With Regular Expressions in Blazor WebAssembly"},"content":{"rendered":"<p>In this article, we are going to learn how to use regular expressions for user input validation in Blazor WebAssembly applications.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/aspnetcore-features\/UserInputValidationWithRegex\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s get started.<\/p>\n<h2>Regular Expressions<\/h2>\n<p>Regular expressions (<em>regex<\/em> or <em>regexp<\/em> for short) are character sequences that we use to match patterns on strings. Every major programming language has a regex engine embedded in it and C#, of course, is no exception.<\/p>\n<p>When working in a Blazor WebAssembly application, we can easily embed complex validations in our data model using regular expressions in combination with data annotations.<\/p>\n<h2>Example Project: Employee Registration Form<\/h2>\n<p>To test all our examples we are going to create a simple Blazor WebAssembly client application. It hosts a single page with a hypothetical employee registration form.<\/p>\n<p>We will create a new Blazor WebAssembly project and add an <code>EmployeeRegistration.razor<\/code> page and a model for our form in <code>EmployeeRegistrationModel.cs<\/code> :<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_01-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-70370 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_01-3.png\" alt=\"Regex Validation Solution\" width=\"348\" height=\"409\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_01-3.png 348w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_01-3-255x300.png 255w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/a><\/p>\n<h3>Basic Model With Data Annotations<\/h3>\n<p>Now, let&#8217;s add the <code>EmployeeRegistrationModel<\/code> class. It contains properties matching each of the data fields in our form:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using System.ComponentModel.DataAnnotations;\r\n\r\nnamespace UserInputValidationWithRegex.Models\r\n{\r\n    public class EmployeeRegistrationModel\r\n    {\r\n        [Required]\r\n        public string Name { get; set; }\r\n\r\n        [Required]\r\n        public string Address { get; set; }\r\n\r\n        [Required]\r\n        public string ZipCode { get; set; }\r\n\r\n        [Required]\r\n        public string SocialSecurityNumber { get; set; }\r\n\r\n        [Required]\r\n        public string Email { get; set; }\r\n\r\n        [Required]\r\n        public string Username { get; set; }\r\n\r\n        [Required]\r\n        public string Password { get; set; }\r\n\r\n        [Required]\r\n        public string PhoneNumber { get; set; }\r\n    }\r\n}<\/pre>\n<p>First, we include the data annotations namespace. Then, we use the <code>Required<\/code> attribute to make all fields mandatory. Yes, we will ask our users to fill out our form completely.\u00a0<\/p>\n<p>Next, our page component will be based on a standard <code>EditForm<\/code> component, some input controls, and a couple of other validation related components:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">        @page \"\/\"\r\n\r\n@using UserInputValidationWithRegex.Models\r\n\r\n&lt;PageTitle&gt;@pageTitle&lt;\/PageTitle&gt;\r\n&lt;h1&gt;@pageTitle&lt;\/h1&gt;\r\n\r\n&lt;EditForm Model=\"@model\" OnValidSubmit=\"@HandleValidSubmit\"&gt;\r\n    &lt;DataAnnotationsValidator \/&gt;\r\n    &lt;ValidationSummary \/&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"name\" class=\"form-label\"&gt;Employee Name&lt;\/label&gt;\r\n        &lt;InputText id=\"name\" class=\"form-control\" @bind-Value=\"model.Name\" aria-describedby=\"nameHelp\" \/&gt;\r\n        &lt;div id=\"nameHelp\" class=\"form-text\"&gt;Employee's first, middle and last names.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"address\" class=\"form-label\"&gt;Address&lt;\/label&gt;\r\n        &lt;InputText id=\"address\" class=\"form-control\" @bind-Value=\"model.Address\" aria-describedby=\"addressHelp\" \/&gt;\r\n        &lt;div id=\"addressHelp\" class=\"form-text\"&gt;Employee's address.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-5\"&gt;\r\n        &lt;label for=\"zipCode\" class=\"form-label\"&gt;Zip Code&lt;\/label&gt;\r\n        &lt;InputText id=\"zipCode\" class=\"form-control\" @bind-Value=\"model.ZipCode\" aria-describedby=\"zipCodeHelp\" \/&gt;\r\n        &lt;div id=\"zipCodeHelp\" class=\"form-text\"&gt;Zip Code.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-5\"&gt;\r\n        &lt;label for=\"socialSecurityNumber\" class=\"form-label\"&gt;Social Security Number&lt;\/label&gt;\r\n        &lt;InputText id=\"socialSecurityNumber\"\r\n                   class=\"form-control\"\r\n                   @bind-Value=\"model.SocialSecurityNumber\"\r\n                   aria-describedby=\"socialSecurityNumberHelp\" \/&gt;\r\n        &lt;div id=\"socialSecurityNumberHelp\" class=\"form-text\"&gt;Employee's social security number.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"email\" class=\"form-label\"&gt;E-Mail&lt;\/label&gt;\r\n        &lt;InputText id=\"email\" class=\"form-control\" @bind-Value=\"model.Email\" aria-describedby=\"emailHelp\" \/&gt;\r\n        &lt;div id=\"emailHelp\" class=\"form-text\"&gt;We'll never share your email with anyone else.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"username\" class=\"form-label\"&gt;Username&lt;\/label&gt;\r\n        &lt;InputText id=\"username\" class=\"form-control\" @bind-Value=\"model.Username\" aria-describedby=\"usernameHelp\" \/&gt;\r\n        &lt;div id=\"usernameHelp\" class=\"form-text\"&gt;Choose a unique username.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"password\" class=\"form-label\"&gt;Password&lt;\/label&gt;\r\n        &lt;InputText type=\"password\"\r\n                   id=\"password\"\r\n                   class=\"form-control\"\r\n                   @bind-Value=\"model.Password\"\r\n                   aria-describedby=\"passwordHelp\" \/&gt;\r\n        &lt;div id=\"passwordHelp\" class=\"form-text\"&gt;Choose a strong password.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"mb-3 col-9\"&gt;\r\n        &lt;label for=\"phone\" class=\"form-label\"&gt;Phone Number&lt;\/label&gt;\r\n        &lt;InputText id=\"phone\" class=\"form-control\" @bind-Value=\"model.PhoneNumber\" aria-describedby=\"phoneHelp\" \/&gt;\r\n        &lt;div id=\"phoneHelp\" class=\"form-text\"&gt;Main contact phone number.&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;button type=\"submit\" class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;\r\n\r\n&lt;\/EditForm&gt;\r\n\r\n@code {\r\n    private string pageTitle = \"Employee Registration Form\";\r\n    private EmployeeRegistrationModel model = new();\r\n\r\n    private void HandleValidSubmit()\r\n    {\r\n        \/\/ TODO: Handle form data\r\n    }\r\n}\r\n<\/pre>\n<p>Right after the page directive, we include our Models namespace so this page has access to our <code>EmployeeFormModel<\/code> class.<\/p>\n<p>The next important element is our <code>EditForm<\/code> component, whose <code>Model<\/code> attribute is set to a private field <code>model<\/code> defined in the code section at the bottom of the page. Also, we will set the form&#8217;s <code>OnValidSubmit<\/code> attribute to the <code>HandleValidInput<\/code> private method defined in the code section as well.<\/p>\n<p>We must add a <code>ValidationSummary<\/code> component inside our form so all the validation messages are displayed on the screen. Also, a <code>DataAnnotationsValidator<\/code> inspects our form&#8217;s model object and calls validation against data annotations.<\/p>\n<p>Finally, we add a set of <code>InputText<\/code> components and a simple submit button. We bind <code>InputText<\/code> components to each of our model&#8217;s properties using the <code>@bind-Value<\/code> directive.<\/p>\n<div style=\"padding: 20px; border-left: 5px gray solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To learn more about the form validation in Blazor WebAssembly, you can read <a href=\"https:\/\/code-maze.com\/blazor-webassembly-forms-form-validation\/\" target=\"_blank\" rel=\"noopener\">our article here<\/a>. Also, if you want to see the custom validation in action, you can read more <a href=\"https:\/\/code-maze.com\/custom-validation-in-blazor-webassembly\/\" target=\"_blank\" rel=\"noopener\">about that here<\/a>.<\/div>\n<p>At this point, we should be able to successfully run our project and enter data in our form. If you try to submit the form leaving some fields empty the <code>Required<\/code> annotations we have already in place should trigger some validation error messages:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70371\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_02.png\" alt=\"Regular Expressions Form\" width=\"981\" height=\"887\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_02.png 981w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_02-300x271.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_02-768x694.png 768w\" sizes=\"auto, (max-width: 981px) 100vw, 981px\" \/><\/a><\/p>\n<p>Perfect. But that&#8217;s not what we&#8217;re here for.<\/p>\n<h2>Validate Blazor WebAssembly Form Fields With Regex<\/h2>\n<p>Now let&#8217;s explore how we can use regular expressions to easily implement more complex validations.<\/p>\n<h3>Employee Name<\/h3>\n<p>We want all employee names in our database to be as authentic as possible. One step we can take towards that is to check that the data input in that field looks like a person&#8217;s name.<\/p>\n<p>Considering only the English language, a typical person&#8217;s name will be composed of uppercase and lowercase letters, spaces, and symbols like periods <code>.<\/code>, hyphens <code>-<\/code> or apostrophes <code>'<\/code>. On the other hand, a person&#8217;s name would never contain numeric characters or symbols like backslashes <code>\\<\/code> or asterisks <code>*<\/code>. Finally, we consider that any given name must be a minimum of two characters long.<\/p>\n<p>Let&#8217;s come up with a regular expression that checks all of the previous conditions and apply it to our form model using data annotations:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^[a-zA-Z\\s.\\-']{2,}$\", ErrorMessage = \"Employee name contains invalid characters.\")]\r\npublic string Name { get; set; }<\/pre>\n<p>Creating regular expressions is a deep topic and we won&#8217;t be explaining the basics. For now, we are good knowing that <code>a-z<\/code> and <code>A-Z<\/code> both match the ranges of characters that together comprehend all letters in the alphabet regardless of their case. At the same time, <code>\\s<\/code> matches spaces, <code>.<\/code> periods and <code>'<\/code> apostrophes. We must escape the hyphen <code>\\-<\/code> to avoid ambiguities with the range syntax. Finally, <code>{2,}<\/code> is a quantifier and validates that the total length of the string is equaled to or exceeds two.<\/p>\n<p>That&#8217;s it, we have implemented a relatively complex validation logic with a single line of code:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_03-2-e1651994572304.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-70372\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_03-2-e1651994572304.png\" alt=\"Regular Expressions Validate Name\" width=\"694\" height=\"149\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_03-2-e1651994572304.png 694w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/05\/validation_with_regex_03-2-e1651994572304-300x64.png 300w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/a><\/p>\n<h3>Address<\/h3>\n<p>Addresses usually contain a street number and name at the beginning. Following that, we will require to enter the city name and state separated by a period. These are some examples of valid addresses:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">23839 Arroyo Park Rd. Dayton, Minnesota(MN)\r\n365 Payson St. San Dimas, California(CA)<\/pre>\n<p>A new expression to match all that logic will be significantly more complex. However, its building blocks remain the same:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^[0-9]+\\s[a-zA-Z\\s\\-']{2,}.\\s?[a-zA-Z\\s\\(\\),]{2,}$\", ErrorMessage = \"Wrong address format.\")]\r\npublic string Address { get; set; }<\/pre>\n<p>Here, we use a series of character matchers and quantifiers along with some fixed characters to define the different sections of our address format.<\/p>\n<p>For instance, <code>[0-9]+<\/code> will match a street number with one or more digits followed by a fixed space <code>\\s<\/code>. Next, the street name matcher <code>[a-zA-Z\\s\\-']{2,}<\/code> accepts at least two letters followed by a period and an optional space <code>.\\s?<\/code> and so on.<\/p>\n<h3>Zip Code<\/h3>\n<p>Zipcodes in the United States come in two flavors: A basic zip code is just five digits. There are, as well, extended codes adding four extra digits that may or may not be separated from the first five by a hyphen.<\/p>\n<p>According to that, all these would valid zipcodes:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">12345\r\n12345-6789\r\n123456789<\/pre>\n<p>To build a regular expression that matches exactly our rules for zip codes we will use the alternate token <code>|<\/code>. We will provide two expressions and get a positive match whenever the input string fits either one or the other:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^[0-9]{5}$|^[0-9]{5}-?[0-9]{4}$\", ErrorMessage = \"Invalid zipcode format\")]\r\npublic string ZipCode { get; set; }<\/pre>\n<h3>Social Security Number<\/h3>\n<p>United States&#8217; social security number format is <code>000-00-0000<\/code>. However, not all digits are valid in every position. For instance, <code>666<\/code> or <code>900<\/code> to <code>999<\/code> aren&#8217;t valid for the first segment and none of the segments can consist of only zeros.<\/p>\n<p>This time, we use the negative lookahead assertion <code>?!<\/code> to ensure that a certain set of expressions do not match the pattern without consuming string positions itself:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^(?!(000|666|9))\\d{3}-(?!00)\\d{2}-(?!0000)\\d{4}$\", ErrorMessage = \"Invalid SSN\")]\r\npublic string SocialSecurityNumber { get; set; }<\/pre>\n<h3>Username and Password<\/h3>\n<p>Typically, a username input field would only allow a certain length and a specific subset of characters.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^[\\w.\\-]{2,18}$\", ErrorMessage = \"Invalid username.\")]\r\npublic string Username { get; set; }<\/pre>\n<p>Here, we simplify the expression by using a new matcher <code>\\w<\/code> that is equivalent to <code>[a-zA-Z0-9_]<\/code>.<\/p>\n<p>Also, we use a quantifier to limit the length of the string to eight-teen characters. However, it is probably better to use the <code>MaxLength<\/code> data annotation attribute for that.<\/p>\n<p>Passwords, on the other hand, usually require at least one occurrence of certain character types. We will require our new employee to provide a password that matches the following rules:<\/p>\n<ul>\n<li>At least one\n<ul>\n<li>number (0-9)<\/li>\n<li>uppercase letter<\/li>\n<li>lowercase letter<\/li>\n<li>non-alpha-numeric character<\/li>\n<\/ul>\n<\/li>\n<li>Password length is between 8 and 32 characters with no spaces<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^(?=.*\\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\\w\\d\\s:])([^\\s]){8,32}$\", \r\n                    ErrorMessage = \"Password doesn't meet security rules.\")]\r\npublic string Password { get; set; }<\/pre>\n<p>Checking that there&#8217;s at least one occurrence of a certain type of character is the tricky part. However, we can achieve it using the positive lookahead assertion <code>?=<\/code>. It checks that a given pattern appears in a string without consuming string positions itself.<\/p>\n<h3>Email<\/h3>\n<p>Validating email addresses can be rather complex. Anyway, we can go for something simple that does the job just fine:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^((?!\\.)[\\w-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$\", ErrorMessage = \"Invalid email address.\")]\r\npublic string Email { get; set; }<\/pre>\n<h3>Phone Number<\/h3>\n<p>Finally, let&#8217;s validate our employee&#8217;s phone number. Phone numbers in the united states consist of ten digits and may be preceded by the country code <code>+1<\/code>. Additionally, some people like to insert spaces to separate groups of digits <code>+1 123 456 7890<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">[Required]\r\n[RegularExpression(@\"^([+]?\\d{1,2}[-\\s]?|)\\d{3}[-\\s]?\\d{3}[-\\s]?\\d{4}$\", ErrorMessage = \"Invalid phone number.\")]\r\npublic string PhoneNumber { get; set; }<\/pre>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned what regular expressions are and why they are useful for user input validation.<\/p>\n<p>We have learned how to integrate regular expressions in our Blazor WebAssembly application using data annotation attributes and, finally, we have implemented various complex validations in an example form.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to use regular expressions for user input validation in Blazor WebAssembly applications. Let&#8217;s get started. Regular Expressions Regular expressions (regex or regexp for short) are character sequences that we use to match patterns on strings. Every major programming language has a regex engine embedded in it [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62188,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[683,684],"tags":[685,686,727,1257,743],"class_list":["post-70366","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blazor","category-blazor-webassembly","tag-blazor","tag-blazor-webassembly","tag-forms-validation","tag-regular-expressions","tag-validation","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Validate User Input With Regular Expressions in Blazor WebAssembly<\/title>\n<meta name=\"description\" content=\"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Validate User Input With Regular Expressions in Blazor WebAssembly\" \/>\n<meta property=\"og:description\" content=\"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-23T06:00:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-23T06:17:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Validate User Input With Regular Expressions in Blazor WebAssembly\",\"datePublished\":\"2022-05-23T06:00:04+00:00\",\"dateModified\":\"2022-05-23T06:17:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\"},\"wordCount\":1232,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png\",\"keywords\":[\"Blazor\",\"Blazor WebAssembly\",\"Forms Validation\",\"Regular Expressions\",\"validation\"],\"articleSection\":[\"Blazor\",\"Blazor WebAssembly\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\",\"url\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\",\"name\":\"Validate User Input With Regular Expressions in Blazor WebAssembly\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png\",\"datePublished\":\"2022-05-23T06:00:04+00:00\",\"dateModified\":\"2022-05-23T06:17:03+00:00\",\"description\":\"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png\",\"width\":1100,\"height\":620,\"caption\":\"Blazor WebAssembly\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Validate User Input With Regular Expressions in Blazor WebAssembly\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Validate User Input With Regular Expressions in Blazor WebAssembly","description":"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/","og_locale":"en_US","og_type":"article","og_title":"Validate User Input With Regular Expressions in Blazor WebAssembly","og_description":"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.","og_url":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/","og_site_name":"Code Maze","article_published_time":"2022-05-23T06:00:04+00:00","article_modified_time":"2022-05-23T06:17:03+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Validate User Input With Regular Expressions in Blazor WebAssembly","datePublished":"2022-05-23T06:00:04+00:00","dateModified":"2022-05-23T06:17:03+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/"},"wordCount":1232,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png","keywords":["Blazor","Blazor WebAssembly","Forms Validation","Regular Expressions","validation"],"articleSection":["Blazor","Blazor WebAssembly"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/","url":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/","name":"Validate User Input With Regular Expressions in Blazor WebAssembly","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png","datePublished":"2022-05-23T06:00:04+00:00","dateModified":"2022-05-23T06:17:03+00:00","description":"Validate User Input With Regular Expressions using regular expressions in combination with data annotations.","breadcrumb":{"@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-blazor-wasm.png","width":1100,"height":620,"caption":"Blazor WebAssembly"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/validate-input-regular-expressions-blazor-webassembly\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Validate User Input With Regular Expressions in Blazor WebAssembly"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=70366"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70366\/revisions"}],"predecessor-version":[{"id":70487,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70366\/revisions\/70487"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62188"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=70366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=70366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=70366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}