<commit_before>import { AbstractControl, ValidationErrors, Validators } from '@angular/forms';
import { CreditCard } from './shared/credit-card';

export class CreditCardValidator {
  static validateCCNumber(control: AbstractControl): ValidationErrors|null {
    if (Validators.required(control) !== undefined && Validators.required(control) !== null) {
      return {'ccNumber': true};
    }

    let num = control.value.toString().replace(/\s+|-/g, '');

    if (!/^\d+$/.test(num)) {
      return {'ccNumber': true};
    }

    let card = CreditCard.cardFromNumber(num);

    if (!card) {
      return {'ccNumber': true};
    }

    const upperlength = card.length[card.length.length - 1];
    if (
      card.length.includes(num.length) && (card.luhn === false || CreditCard.luhnCheck(num)) ||
      num.length > upperlength
    ) {
      return null;
    }
<commit_msg>Ensure input cc number is correctly validated when user enters excess characters<commit_after>import { AbstractControl, ValidationErrors, Validators } from '@angular/forms';
import { CreditCard } from './shared/credit-card';

export class CreditCardValidator {
  static validateCCNumber(control: AbstractControl): ValidationErrors|null {
    if (Validators.required(control) !== undefined && Validators.required(control) !== null) {
      return {'ccNumber': true};
    }

    let num = control.value.toString().replace(/\s+|-/g, '');

    if (!/^\d+$/.test(num)) {
      return {'ccNumber': true};
    }

    let card = CreditCard.cardFromNumber(num);

    if (!card) {
      return {'ccNumber': true};
    }

    const upperlength = card.length[card.length.length - 1];
    if (card.length.includes(num.length) && (card.luhn === false || CreditCard.luhnCheck(num))) {
      return null;
    }

    if (num.length > upperlength) {
      const registeredNum = num.substring(0, upperlength);
      if (CreditCard.luhnCheck(registeredNum)) {
        return null;
      }
    }

{'fraction_non_alphanumeric': 0.15289892252437148, 'fraction_numerical': 0.0015392508978963571, 'mean_word_length': 3.314159292035398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2858213', 'n_tokens_mistral': 595, 'n_tokens_neox': 569, 'n_words': 128}