.net - Is there any simpler way to check if string entered math to "digitsPX" or "digits%"? -


I need to parse the html values ​​for the top, left, width and height.
The user wants to, but can input anything, but I need to refuse to enter the wrong values ​​like "px 100" and etc. I need to make sure that the string he inserted is something like this:
100px
100%
-100px
-100%

Where 100 Any number Might be possible.

I tried to code it, but there should be a lot of inquiry, so I think there may be a better solution.)

  // Check if in test_str Signs other than the personal string include IStringContainsSymbolsOtherThan (string test_str, list & lt; char & gt; symbols) {if (string.IsNullOrEmpty (test_str)) return null; For (int i = 0; i & lt; test_str.Length; i ++) if (! Symbol (test_str [i])) test_str [i] return. Toasting (); Return tap; } / / The error in saying what is wrong with the entered value (what is not needed) should return the private string GetExceptionMsgFromIntegerValidating (string wall) {if (string.IsNullOrthly (val)) "Price can not be empty"; & Lt; Four & gt; Accepted_symbols = new list & lt; Char & gt; (New four [] ['-', 'P', 'P', 'X', 'X', '%', '0', '1', '2', '3', '4' '5', '6', '7', '8', '9'}); String possible_bad_symbol = null; If (! String.IsNullOrEmpty (possible_bad_symbol = IsStringContainsSymbolsOtherThan (val, allowed_symbols)) "Unexpected symbol in returned value" "+ potential_bad_combole +" \ ""; If (Well Canton ("-") & amp;! Val. Start ("-") returns "Negative numbers should start with zero"; If (val.EndsWith ("px")) {string test_int = val.Replace ("px", ""); If (string.IsNullOrEmptE (test_int)) "Some digits should be entered before 'px';"; // This is where I think that I need to check in some other way, instead of strict coding in all possible circumstances, for example // user input "100pxpx%"} and if (val.EndsWith ( "%")) {} And return "Value entered in wrong format"; Return tap; This is an ideal scenario for regular expression:    

: - (^ [1-9] + pixels $?). (: ^ [1-9] + pixels $?). (: ^ - [1-9] +% $). (?: ^ [1- 9] +% $). (?: ^ 0 $)

Note: This is probably not the best regular expression, but

update

Even better regular expressions:

  • Just 0
  • starts without a minus sign, 1 Or greater than 1 and ends with px .
  • starts with a minus sign, ends with 1 or more number 1 and px .
  • starts without a minus sign, starts at 1 or more points 1 and ends with % .
  • starts with a minus sign, starts at number 1 or greater and ends with % .

Comments

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -