Projet

Général

Profil

Révision ba09eb79

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/components/number.inc
802 802
 * Based on http://stackoverflow.com/questions/5917082/regular-expression-to-match-numbers-with-or-without-commas-and-decimals-in-text.
803 803
 */
804 804
function webform_number_format_match($value, $point, $separator) {
805
  return preg_match('/^-? ?\d{1,3}(?:' . ($separator ? (preg_quote($separator, '/') . '?') : '') . '\d{2,3})*(?:' . preg_quote($point, '/') . '\d+)?$/', $value);
805
  // A valid number is:
806
  //   1. optional minus sign
807
  //   2. optional space
808
  //   3. the rest of the string can't be just a decimal or blank.
809
  //   3. optional integer portion, with thousands separators
810
  //   4. optional decimal portion, starting is a decimal separator
811

  
812
  $thousands = $separator ? (preg_quote($separator, '/') . '?') : '';
813
  $decimal = preg_quote($point, '/');
814
  return preg_match("/
815
                    ^               # Start of string
816
                    -?              # Optional minus sign
817
                    \ ?             # Optional space
818
                    (?!\.?$)        # Assert looking ahead, not just a decimal or nothing
819
                      (?:           # Interger portion (non-grouping)
820
                        \d{1,3}     #   1 to 3 digits
821
                        (?:         #   Thousands group(s)
822
                        $thousands  #     Optional thousands separator
823
                        \d{2,3}     #     2 or 3 digits. Some countries use groups of 2 sometimes
824
                      )*            #   0 or more of these thousands groups
825
                    )?              # End of optional integer portion
826
                    (?:             # Decimal portion (non-grouping)
827
                      $decimal      #   Decimal point
828
                      \d*           #   0 or more digits
829
                    )?              # End of optional decimal portion
830
                    $
831
                    /x", $value);
806 832
}
807 833

  
808 834
/**

Formats disponibles : Unified diff