| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "components/autofill/core/browser/field_types.h" | 10 #include "components/autofill/core/browser/field_types.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 class Time; | 13 class Time; |
| 14 } // namespace base | 14 } // namespace base |
| 15 | 15 |
| 16 namespace autofill { | 16 namespace autofill { |
| 17 | 17 |
| 18 class CreditCard; |
| 19 |
| 18 // Constants for the length of a CVC. | 20 // Constants for the length of a CVC. |
| 19 static const size_t GENERAL_CVC_LENGTH = 3; | 21 static const size_t GENERAL_CVC_LENGTH = 3; |
| 20 static const size_t AMEX_CVC_LENGTH = 4; | 22 static const size_t AMEX_CVC_LENGTH = 4; |
| 21 | 23 |
| 22 // Returns true if |year| and |month| describe a date later than |now|. | 24 // Returns true if |year| and |month| describe a date later than |now|. |
| 23 // |year| must have 4 digits. | 25 // |year| must have 4 digits. |
| 24 bool IsValidCreditCardExpirationDate(int year, | 26 bool IsValidCreditCardExpirationDate(int year, |
| 25 int month, | 27 int month, |
| 26 const base::Time& now); | 28 const base::Time& now); |
| 27 | 29 |
| 28 // Returns true if |text| looks like a valid credit card number. | 30 // Returns true if |text| looks like a valid credit card number. |
| 29 // Uses the Luhn formula to validate the number. | 31 // Uses the Luhn formula to validate the number. |
| 30 bool IsValidCreditCardNumber(const base::string16& text); | 32 bool IsValidCreditCardNumber(const base::string16& text); |
| 31 | 33 |
| 32 // Returns true if |code| looks like a valid credit card security code | 34 // Returns true if |code| looks like a valid credit card security code |
| 33 // for the given credit card type. | 35 // for the given credit card type. |
| 34 bool IsValidCreditCardSecurityCode(const base::string16& code, | 36 bool IsValidCreditCardSecurityCode(const base::string16& code, |
| 35 const base::StringPiece card_type); | 37 const base::StringPiece card_type); |
| 36 | 38 |
| 37 // Returns true if |text| is a supported card type and a valid credit card | 39 // Returns true if |text| is a supported card type and a valid credit card |
| 38 // number. |error_message| can't be null and will be filled with the appropriate | 40 // number. |error_message| can't be null and will be filled with the appropriate |
| 39 // error message. | 41 // error message. |
| 40 bool IsValidCreditCardNumberForBasicCardNetworks( | 42 bool IsValidCreditCardNumberForBasicCardNetworks( |
| 41 const base::string16& text, | 43 const base::string16& text, |
| 42 const std::set<std::string>& supported_basic_card_networks, | 44 const std::set<std::string>& supported_basic_card_networks, |
| 43 base::string16* error_message); | 45 base::string16* error_message); |
| 44 | 46 |
| 47 // Returns whether |card| has a non-empty number and cardholder name. Server |
| 48 // cards will have a non-empty number. |
| 49 bool CreditCardHasNumberAndName(const autofill::CreditCard& card, |
| 50 const std::string& app_locale); |
| 51 |
| 52 // A card is complete for Payment Request if it's not expired, its number is not |
| 53 // empty (a server card fills this condition) and there is a cardholder name. |
| 54 // If there is missing information, will return false and fill |missing_info| |
| 55 // with a proper string for display. |missing_info| can be nullptr if the caller |
| 56 // doesn't care about the missing info. |
| 57 // TODO(crbug.com/709776): Check for billing address association. |
| 58 bool IsCompleteForPaymentRequest(const CreditCard& credit_card, |
| 59 const std::string& app_locale, |
| 60 base::string16* missing_info); |
| 61 |
| 45 // Returns true if |text| looks like a valid e-mail address. | 62 // Returns true if |text| looks like a valid e-mail address. |
| 46 bool IsValidEmailAddress(const base::string16& text); | 63 bool IsValidEmailAddress(const base::string16& text); |
| 47 | 64 |
| 48 // Returns true if |text| is a valid US state name or abbreviation. It is case | 65 // Returns true if |text| is a valid US state name or abbreviation. It is case |
| 49 // insensitive. Valid for US states only. | 66 // insensitive. Valid for US states only. |
| 50 bool IsValidState(const base::string16& text); | 67 bool IsValidState(const base::string16& text); |
| 51 | 68 |
| 52 // Returns whether the number contained in |text| is valid for the specified | 69 // Returns whether the number contained in |text| is valid for the specified |
| 53 // |country_code|. Callers should cache the result as the parsing is expensive. | 70 // |country_code|. Callers should cache the result as the parsing is expensive. |
| 54 bool IsValidPhoneNumber(const base::string16& text, | 71 bool IsValidPhoneNumber(const base::string16& text, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 // Returns the expected CVC length based on the |card_type|. | 87 // Returns the expected CVC length based on the |card_type|. |
| 71 size_t GetCvcLengthForCardType(const base::StringPiece card_type); | 88 size_t GetCvcLengthForCardType(const base::StringPiece card_type); |
| 72 | 89 |
| 73 // Returns true if |value| appears to be a UPI Virtual Payment Address. | 90 // Returns true if |value| appears to be a UPI Virtual Payment Address. |
| 74 // https://upipayments.co.in/virtual-payment-address-vpa/ | 91 // https://upipayments.co.in/virtual-payment-address-vpa/ |
| 75 bool IsUPIVirtualPaymentAddress(const base::string16& value); | 92 bool IsUPIVirtualPaymentAddress(const base::string16& value); |
| 76 | 93 |
| 77 } // namespace autofill | 94 } // namespace autofill |
| 78 | 95 |
| 79 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ | 96 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_VALIDATION_H_ |
| OLD | NEW |