import type { ICompletionAnswer } from '@/views/Survey/views/Preview/components/questions/types/previewCompletion';
import { getLanguage } from '@/views/Survey/views/Preview/js/language';
import type { ITranslatedText } from '@/views/Survey/views/Preview/components/questions/types/translatedText';

/**
 * 验证手机号
 * @param answer {ICompletionAnswer} 答案
 * @param translatedText {ITranslatedText} 语言转换文本
 */
export function validatePhone(
  answer: string,
  translatedText = getLanguage(['zh']) as ITranslatedText
) {
  let isError: boolean;

  isError = !/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(answer);
  return isError ? translatedText.PleaseEnterACorrectPhone : '';
}
