Snippet List
Format Number Based on Regular Expression
**Examples**
>*{{.1234|regex_comma_number:'%.4f'}}
>*'0.1234'
>*{{100|regex_comma_number:'%i'}}
>*'100'
>*{{ 234.5678|regex_comma_number:'%.4f'}}
>*'234.5678'
>*{{234.5678|regex_comma_number:'$%.4f'}}
>*'$234.5678'
>*{{1000|regex_comma_number:'%i'}}
>*'1,000'
>*{{1234.5678|regex_comma_number:'%.4f'}}
>*'1,234.5678'
>*{{1234.5678|regex_comma_number:'$%.4f'}}
>*'$1,234.5678'
>*{{1000000|regex_comma_number:'%i'}}
>*'1,000,000'
>*{{1234567.5678|regex_comma_number:'%.4f'}}
>*'1,234,567.5678'
>*{{1234567.5678|regex_comma_number:'$%.4f'}}
>*'$1,234,567.5678'
>*{{-100|regex_comma_number:'%i'}}
>*'-100'
>*{{-234.5678|regex_comma_number:'%.4f'}}
>*-234.5678'
>*{{-234.5678|regex_comma_number:'$%.4f'}}
>*'$-234.5678'
>*{{-1000|regex_comma_number:'%i'}}
>*'-1,000'
>*{{-1234.5678|regex_comma_number:'%.4f'}}
>*'-1,234.5678'
>*{{-1234.5678|regex_comma_number:'$%.4f'}}
>*'$-1,234.5678'
>*{{-1000000|regex_comma_number:'%i'}}
>*'-1,000,000'
>*{{-1234567.5678|regex_comma_number:'%.4f'}}
>*'-1,234,567.5678'
>*{{-1234567.5678|regex_comma_number:'$%.4f'}}
>*'$-1,234,567.5678'`
- templatetag
- regex
- format
- comma
- number
Some functions and newforms fields for validating credit card numbers, and their expiry dates.
In my project, I have all of the credit card functions in a file called creditcards.py
Just as an overview: To validate a credit card number there are a few steps:
1. Make sure the number only contains digits and spaces. `ValidateCharacters()`
2. Remove spaces so that only numbers are left. `StripToNumbers()`
3. Check that the number validates using the Luhn Checksum `ValidateLuhnChecksum()`
4. Check to see whether the number is valid for the type of card that is selected. This is annoying because you will need to look at another cleaned field before you can check this.
- newforms
- field
- credit-card
- number
- visa
- mastercard
4 snippets posted so far.