Login

Tag "number"

Snippet List

format_thousands

Template filter to format a number so that it's thousands are separated by commas. {{ number|format_thousands }}

  • format
  • string
  • comma
  • decimal
  • number
  • thousands
  • float
Read More

Regex Comma Number

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
Read More

Newforms Validation of Credit Card Numbers

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
Read More

4 snippets posted so far.