Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, the character <code>.</code> is called a dot, or period, or full stop, or decimal point, while a comma is the character: <code>,</code>.</p> <p>Second, you can designate a digit in regex in a character class: <code>[0-9]</code> means any digit between 0 to 9.</p> <p>A dot in regex will match any character, so you need to escape it by means of a backslash (or putting it in a character class).</p> <p>Remember though that the elements in the same character class can be in any order, so that if you want to get something having digits and a dot and use <code>[0-9.]</code> it will match any digit, or a dot.</p> <p>Now, you will need finite quantifiers for your task, which are designated by braces in the form of <code>{m,n}</code> where <code>m</code> is the minimum and <code>n</code> the maximum. If you now use... <code>[0-9.]{1,15}</code> it would mean the character class <code>[0-9.]</code> repeated 1 up to 15 times.</p> <p>But if you use <code>[0-9.]{1,15}</code>, it will also match <code>......</code> or <code>1234</code> (remember I said earlier that the order did not matter.</p> <p>So, applying all this, you get the regex:</p> <pre><code>[0-9]{1,15}\.[0-9]{1,3} </code></pre> <p>Now, since you are doing a validation, you will need anchors to specify that the regex should test the whole string (instead of simply finding a match).</p> <pre><code>^[0-9]{1,15}\.[0-9]{1,3}$ </code></pre> <p>Last, since you can have optional decimals, you will have to use a group and the quantifier <code>?</code> which means 0 or 1:</p> <pre><code>^[0-9]{1,15}(?:\.[0-9]{1,3})?$ </code></pre> <p>In your code, you will create the regex a bit like this:</p> <pre><code>string myString = "123456789.123"; var regexp = new Regex(@"^[0-9]{1,15}(?:\.[0-9]{1,3})?$"); var setMatches = regexp.Matches(myString); foreach (Match match in setMatches) { Console.WriteLine(match.Groups[0].Value); } </code></pre> <p>This will output the decimal if it passed the regex.</p> <p>Or something like this:</p> <pre><code>string myString = "123456789.123"; Match match = Regex.Match(myString, @"^[0-9]{1,15}(?:\.[0-9]{1,3})?$"); if (match.Success) { Console.WriteLine(match.Groups[0].Value); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload