CurrencyOptions

Struct CurrencyOptions 

Source
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: String

Currency symbol (e.g., “$”, “€”, “¥”)

§require_symbol: bool

Require the currency symbol to be present

§allow_space_after_symbol: bool

Allow space after the symbol

§symbol_after_digits: bool

Symbol appears after the digits instead of before

§allow_negatives: bool

Allow negative values

§parens_for_negatives: bool

Use parentheses for negative values instead of minus sign

§negative_sign_before_digits: bool

Negative sign appears before the digits

§negative_sign_after_digits: bool

Negative sign appears after the digits

§allow_negative_sign_placeholder: bool

Allow space placeholder for negative sign (e.g., “R 123” and “R-123”)

§thousands_separator: char

Thousands separator character

§decimal_separator: char

Decimal separator character

§allow_decimal: bool

Allow decimal portion

§require_decimal: bool

Require 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: bool

Allow space after digits

Implementations§

Source§

impl CurrencyOptions

Source

pub fn new() -> Self

Create a new CurrencyOptions with default values

Examples found in repository?
examples/currency_usage.rs (line 15)
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}
Source

pub fn symbol(self, symbol: impl Into<String>) -> Self

Set the currency symbol

Examples found in repository?
examples/currency_usage.rs (line 16)
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}
Source

pub fn require_symbol(self, require: bool) -> Self

Set whether symbol is required

Examples found in repository?
examples/currency_usage.rs (line 55)
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}
Source

pub fn allow_space_after_symbol(self, allow: bool) -> Self

Set whether to allow space after symbol

Examples found in repository?
examples/currency_usage.rs (line 19)
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}
Source

pub fn symbol_after_digits(self, after: bool) -> Self

Set whether symbol appears after digits

Source

pub fn allow_negatives(self, allow: bool) -> Self

Set whether negatives are allowed

Source

pub fn parens_for_negatives(self, use_parens: bool) -> Self

Set whether to use parentheses for negatives

Examples found in repository?
examples/currency_usage.rs (line 68)
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}
Source

pub fn thousands_separator(self, sep: char) -> Self

Set thousands separator character

Examples found in repository?
examples/currency_usage.rs (line 17)
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}
Source

pub fn decimal_separator(self, sep: char) -> Self

Set decimal separator character

Examples found in repository?
examples/currency_usage.rs (line 18)
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}
Source

pub fn allow_decimal(self, allow: bool) -> Self

Set whether decimals are allowed

Source

pub fn require_decimal(self, require: bool) -> Self

Set whether decimal is required

Source

pub fn digits_after_decimal(self, digits: Vec<usize>) -> Self

Set allowed digits after decimal

Examples found in repository?
examples/currency_usage.rs (line 78)
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}
Source

pub fn negative_sign_before_digits(self, before: bool) -> Self

Set whether negative sign appears before digits

Examples found in repository?
examples/currency_usage.rs (line 30)
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}
Source

pub fn negative_sign_after_digits(self, after: bool) -> Self

Set whether negative sign appears after digits

Source

pub fn allow_negative_sign_placeholder(self, allow: bool) -> Self

Set whether to allow negative sign placeholder

Examples found in repository?
examples/currency_usage.rs (line 44)
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}
Source

pub fn allow_space_after_digits(self, allow: bool) -> Self

Set whether to allow space after digits

Trait Implementations§

Source§

impl Clone for CurrencyOptions

Source§

fn clone(&self) -> CurrencyOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CurrencyOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CurrencyOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.