Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a question for you guys about a regular expression i want to build.

 

I have a string that i want to test. I have my pattern that should be 1 to X times in my string. Thats works.

 

But also, my customer can pass an empty value for this string. If my customer pass nothing, i want my regular expression to succeed also cause i accept empty value for certain textbox. I cant figure out how to manage an empty value in my string.

 

Hope someone can give me a hint on that.

 

Thanks in advance.

Posted

will the "*" (0 or more) operator work for you? or perhaps "^0" ? You can try oring using the pipe | to say "Either my regex or nothing". I think the ^ operator is what you seek, though.

 

Also, why not just do a check for empty string and then apply your regex?

if (value == "" || Regex.Matches(...)) {... }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...