pub struct CurrencyOptions {Show 15 fields
pub symbol: String,
pub require_symbol: bool,
pub allow_space_after_symbol: bool,
pub symbol_after_digits: bool,
pub allow_negatives: bool,
pub parens_for_negatives: bool,
pub negative_sign_before_digits: bool,
pub negative_sign_after_digits: bool,
pub allow_negative_sign_placeholder: bool,
pub thousands_separator: char,
pub decimal_separator: char,
pub allow_decimal: bool,
pub require_decimal: bool,
pub digits_after_decimal: Vec<usize>,
pub allow_space_after_digits: bool,
}Expand description
Options for currency validation
This struct provides configuration for validating currency strings with support for various formats, symbols, and regional conventions.
Fields§
§symbol: StringCurrency symbol (e.g., “$”, “€”, “¥”)
require_symbol: boolRequire the currency symbol to be present
allow_space_after_symbol: boolAllow space after the symbol
symbol_after_digits: boolSymbol appears after the digits instead of before
allow_negatives: boolAllow negative values
parens_for_negatives: boolUse parentheses for negative values instead of minus sign
negative_sign_before_digits: boolNegative sign appears before the digits
negative_sign_after_digits: boolNegative sign appears after the digits
allow_negative_sign_placeholder: boolAllow space placeholder for negative sign (e.g., “R 123” and “R-123”)
thousands_separator: charThousands separator character
decimal_separator: charDecimal separator character
allow_decimal: boolAllow decimal portion
require_decimal: boolRequire decimal portion
digits_after_decimal: Vec<usize>Allowed number of digits after decimal (e.g., vec![2] for exactly 2 digits)
allow_space_after_digits: boolAllow space after digits
Implementations§
Source§impl CurrencyOptions
impl CurrencyOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new CurrencyOptions with default values
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn symbol(self, symbol: impl Into<String>) -> Self
pub fn symbol(self, symbol: impl Into<String>) -> Self
Set the currency symbol
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn require_symbol(self, require: bool) -> Self
pub fn require_symbol(self, require: bool) -> Self
Set whether symbol is required
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn allow_space_after_symbol(self, allow: bool) -> Self
pub fn allow_space_after_symbol(self, allow: bool) -> Self
Set whether to allow space after symbol
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn symbol_after_digits(self, after: bool) -> Self
pub fn symbol_after_digits(self, after: bool) -> Self
Set whether symbol appears after digits
Sourcepub fn allow_negatives(self, allow: bool) -> Self
pub fn allow_negatives(self, allow: bool) -> Self
Set whether negatives are allowed
Sourcepub fn parens_for_negatives(self, use_parens: bool) -> Self
pub fn parens_for_negatives(self, use_parens: bool) -> Self
Set whether to use parentheses for negatives
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn thousands_separator(self, sep: char) -> Self
pub fn thousands_separator(self, sep: char) -> Self
Set thousands separator character
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn decimal_separator(self, sep: char) -> Self
pub fn decimal_separator(self, sep: char) -> Self
Set decimal separator character
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn allow_decimal(self, allow: bool) -> Self
pub fn allow_decimal(self, allow: bool) -> Self
Set whether decimals are allowed
Sourcepub fn require_decimal(self, require: bool) -> Self
pub fn require_decimal(self, require: bool) -> Self
Set whether decimal is required
Sourcepub fn digits_after_decimal(self, digits: Vec<usize>) -> Self
pub fn digits_after_decimal(self, digits: Vec<usize>) -> Self
Set allowed digits after decimal
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn negative_sign_before_digits(self, before: bool) -> Self
pub fn negative_sign_before_digits(self, before: bool) -> Self
Set whether negative sign appears before digits
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn negative_sign_after_digits(self, after: bool) -> Self
pub fn negative_sign_after_digits(self, after: bool) -> Self
Set whether negative sign appears after digits
Sourcepub fn allow_negative_sign_placeholder(self, allow: bool) -> Self
pub fn allow_negative_sign_placeholder(self, allow: bool) -> Self
Set whether to allow negative sign placeholder
Examples found in repository?
3fn main() {
4 println!("=== Currency Validator Examples ===\n");
5
6 // Example 1: Default USD format
7 println!("1. Default USD format:");
8 let usd_values = vec!["$10,123.45", "10,123.45", "-$99.99", "$.99"];
9 for val in usd_values {
10 println!(" '{}' -> {}", val, is_currency(val, None));
11 }
12
13 // Example 2: Euro (Italian format)
14 println!("\n2. Euro (Italian format - €1.234,56):");
15 let euro_options = CurrencyOptions::new()
16 .symbol("€")
17 .thousands_separator('.')
18 .decimal_separator(',')
19 .allow_space_after_symbol(true);
20
21 let euro_values = vec!["€1.234,56", "€ 1.234,56", "-€10,50"];
22 for val in euro_values {
23 println!(" '{}' -> {}", val, is_currency(val, Some(euro_options.clone())));
24 }
25
26 // Example 3: Chinese Yuan
27 println!("\n3. Chinese Yuan (¥):");
28 let yuan_options = CurrencyOptions::new()
29 .symbol("¥")
30 .negative_sign_before_digits(true);
31
32 let yuan_values = vec!["¥1,234.56", "¥-999.99", "123,456.78"];
33 for val in yuan_values {
34 println!(" '{}' -> {}", val, is_currency(val, Some(yuan_options.clone())));
35 }
36
37 // Example 4: South African Rand
38 println!("\n4. South African Rand (R 123 or R-123):");
39 let rand_options = CurrencyOptions::new()
40 .symbol("R")
41 .thousands_separator(' ')
42 .decimal_separator(',')
43 .negative_sign_before_digits(true)
44 .allow_negative_sign_placeholder(true);
45
46 let rand_values = vec!["R 10 123,45", "R-10 123,45", "R 123,45"];
47 for val in rand_values {
48 println!(" '{}' -> {}", val, is_currency(val, Some(rand_options.clone())));
49 }
50
51 // Example 5: Brazilian Real
52 println!("\n5. Brazilian Real (R$ 1.234,56):");
53 let real_options = CurrencyOptions::new()
54 .symbol("R$")
55 .require_symbol(true)
56 .allow_space_after_symbol(true)
57 .thousands_separator('.')
58 .decimal_separator(',');
59
60 let real_values = vec!["R$ 1.400,00", "R$ 400,00", "$ 1.400,00"];
61 for val in real_values {
62 println!(" '{}' -> {}", val, is_currency(val, Some(real_options.clone())));
63 }
64
65 // Example 6: Parentheses for negatives
66 println!("\n6. Parentheses for negatives:");
67 let parens_options = CurrencyOptions::new()
68 .parens_for_negatives(true);
69
70 let parens_values = vec!["($1,234.56)", "$1,234.56", "(1,234.56)", "-$1,234.56"];
71 for val in parens_values {
72 println!(" '{}' -> {}", val, is_currency(val, Some(parens_options.clone())));
73 }
74
75 // Example 7: Custom decimal digits
76 println!("\n7. Custom decimal digits (1 or 3 digits):");
77 let custom_decimal_options = CurrencyOptions::new()
78 .digits_after_decimal(vec![1, 3]);
79
80 let custom_values = vec!["$10.5", "$10.123", "$10.12", "$10.1234"];
81 for val in custom_values {
82 println!(" '{}' -> {}", val, is_currency(val, Some(custom_decimal_options.clone())));
83 }
84
85 println!("\n=== All examples completed ===");
86}Sourcepub fn allow_space_after_digits(self, allow: bool) -> Self
pub fn allow_space_after_digits(self, allow: bool) -> Self
Set whether to allow space after digits
Trait Implementations§
Source§impl Clone for CurrencyOptions
impl Clone for CurrencyOptions
Source§fn clone(&self) -> CurrencyOptions
fn clone(&self) -> CurrencyOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more