Use regular expression to check whether a string is a currency or not.

38 times



The following example illustrates the use of a regular expression to check whether a string either represents a currency value or has the correct format to represent a currency value. 

Because the regular expression in this demo is built dynamically, we do not know at design time whether the current culture's currency symbol, decimal sign, or positive and negative signs might be misinterpreted by the regular expression engine as regular expression language operators. To prevent any misinterpretation, the example passes each dynamically generated string to the  method.

The Regex class represents the .NET Framework's regular expression engine. It can be used to quickly parse large amounts of text to find specific character patterns; to extract, edit, replace, or delete text substrings; and to add the extracted strings to a collection to generate a report.