• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java LuhnCheckDigit类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit的典型用法代码示例。如果您正苦于以下问题:Java LuhnCheckDigit类的具体用法?Java LuhnCheckDigit怎么用?Java LuhnCheckDigit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

LuhnCheckDigit类属于org.apache.commons.validator.routines.checkdigit包,在下文中一共展示了LuhnCheckDigit类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateRandomCreditCardNumber

点赞 3

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
public String generateRandomCreditCardNumber() {

            String issuerIdentificationNumber = randomIssuerIdentificationNumber();

            String cardNumberWithoutCheckDigit =
                    format("%s%s",
                            issuerIdentificationNumber,
                            randomNumeric(length - issuerIdentificationNumber.length() - 1));
            try {

                String checkDigit = LuhnCheckDigit.LUHN_CHECK_DIGIT.calculate(cardNumberWithoutCheckDigit);

                return format("%s%s", cardNumberWithoutCheckDigit, checkDigit);

            } catch (CheckDigitException e) {
                throw new RuntimeException(e);
            }
        }
 

开发者ID:seize-the-dave,
项目名称:forgery,
代码行数:19,
代码来源:RandomCreditCardForger.java

示例2: calculate

点赞 2

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
public static String calculate ( String panNUmber){
	
	LuhnCheckDigit   luhn = new LuhnCheckDigit();
	String checkdigit;
	try {
		checkdigit = luhn.calculate(  panNUmber );
	} catch (CheckDigitException e) {
		checkdigit = "CheckDigit.calculate : "+ e.getMessage() ;
		System.out.println(checkdigit);
	}
	return checkdigit ;	
	
}
 

开发者ID:jporras66,
项目名称:cryptocard,
代码行数:14,
代码来源:CheckDigit.java

示例3: shouldForgeCreditCardWithAPan

点赞 2

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
@Test
public void shouldForgeCreditCardWithAPan() {
    // When
    CreditCard forgedCreditCard = new Forgery.Builder().build().forge(CreditCard.class);

    // Then
    assertThat(forgedCreditCard.getPan(), is(notNullValue()));
    assertThat(LuhnCheckDigit.LUHN_CHECK_DIGIT.isValid(forgedCreditCard.getPan()), is(true));
}
 

开发者ID:seize-the-dave,
项目名称:forgery,
代码行数:10,
代码来源:ForgeryTest.java

示例4: shouldProvideARandomValidCreditCardNumberWithCorrectLuhnCheckDigit

点赞 2

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
@Test
public void shouldProvideARandomValidCreditCardNumberWithCorrectLuhnCheckDigit() {
    /// When
    String creditCardNumber = new RandomCreditCardForger().get();

    // Then
    assertThat(LuhnCheckDigit.LUHN_CHECK_DIGIT.isValid(creditCardNumber),
            is(true));
}
 

开发者ID:seize-the-dave,
项目名称:forgery,
代码行数:10,
代码来源:RandomCreditCardForgerTest.java

示例5: testMastercardUsingSeparators

点赞 2

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
/**
 * Test using separators
 */    
public void testMastercardUsingSeparators() {

    String MASTERCARD_REGEX_SEP = "^(5[1-5]\\d{2})(?:[- ])?(\\d{4})(?:[- ])?(\\d{4})(?:[- ])?(\\d{4})$";
    CodeValidator validator = new CodeValidator(MASTERCARD_REGEX_SEP, LuhnCheckDigit.LUHN_CHECK_DIGIT);
    RegexValidator regex    = validator.getRegexValidator();

    // ****** Test Regular Expression ******
    // length 16 and start with a "51-55"
    assertEquals("Number",  "5134567890123456", regex.validate("5134567890123456"));
    assertEquals("Hyphen",  "5134567890123456", regex.validate("5134-5678-9012-3456"));
    assertEquals("Space",   "5134567890123456", regex.validate("5134 5678 9012 3456"));
    assertEquals("MixedA",  "5134567890123456", regex.validate("5134-5678 9012-3456"));
    assertEquals("MixedB",  "5134567890123456", regex.validate("5134 5678-9012 3456"));

    assertFalse("Invalid Separator A",  regex.isValid("5134.5678.9012.3456"));
    assertFalse("Invalid Separator B",  regex.isValid("5134_5678_9012_3456"));
    assertFalse("Invalid Grouping A",   regex.isValid("513-45678-9012-3456"));
    assertFalse("Invalid Grouping B",   regex.isValid("5134-567-89012-3456"));
    assertFalse("Invalid Grouping C",   regex.isValid("5134-5678-901-23456"));

    // *********** Test Validator **********
    assertEquals("Valid-A", "5500000000000004", validator.validate("5500-0000-0000-0004"));
    assertEquals("Valid-B", "5424000000000015", validator.validate("5424 0000 0000 0015"));
    assertEquals("Valid-C", "5301250070000191", validator.validate("5301-250070000191"));
    assertEquals("Valid-D", "5123456789012346", validator.validate("5123456789012346"));
}
 

开发者ID:ManfredTremmel,
项目名称:gwt-commons-validator,
代码行数:30,
代码来源:CreditCardValidatorTest.java

示例6: validate

点赞 1

import org.apache.commons.validator.routines.checkdigit.LuhnCheckDigit; //导入依赖的package包/类
public static boolean validate ( String panNUmber){
	
	LuhnCheckDigit   luhn = new LuhnCheckDigit();
	return luhn.isValid ( panNUmber ) ;	
	
}
 

开发者ID:jporras66,
项目名称:cryptocard,
代码行数:7,
代码来源:CheckDigit.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)