c# - Regular Expression: Search key validation -


please regular expression. working on validating string. value should not contain % , if there % length should more 3 characters including %. % can anywhere in string (dot included).

i come this. validation should happen when % in string. if there no % no validation necessary.

@"^[a-za-z0-9'.]*%"; //{3,}$";

thanks, naveen

examples:

  • "%" - fail
  • "%12" - fail
  • "%123" - pass
  • "%1234" - pass
  • "12%3" - pass
  • "abc%" - pass
  • "abc" - pass
  • "a" - pass
  • "abc" - pass

i don't think needs regex solve, string methods ok:

var valid = !input.contains("%") || input.length > 3; 

if want use regex, here are:

^([^%]+|.{4,})$ 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -