|
@@ -29,6 +29,15 @@ checkLogin();
|
|
upMediaExt:"wmv,avi,wma,mp3,mid"
|
|
upMediaExt:"wmv,avi,wma,mp3,mid"
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
+ $(document).on('blur', '.method-input', function() {
|
|
|
|
+ var methodType = $(this).prev('.method-select').val();
|
|
|
|
+ if (methodType === 'tel' || methodType === 'whatsapp') {
|
|
|
|
+ var formattedValue = formatPhoneNumber($(this).val(), true);
|
|
|
|
+ $(this).val(formattedValue);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
|
|
$('.add-contact-btn').click(function() {
|
|
$('.add-contact-btn').click(function() {
|
|
var contactsContainer = $('#contacts-container');
|
|
var contactsContainer = $('#contacts-container');
|
|
@@ -86,6 +95,16 @@ checkLogin();
|
|
|
|
|
|
methodsContainer.append(methodRow);
|
|
methodsContainer.append(methodRow);
|
|
updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
|
|
updateMethodFields(methodsContainer.find('.contact-method-row:last-child'));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var newRow = methodsContainer.find('.contact-method-row:last-child');
|
|
|
|
+ newRow.find('.method-select').on('change', function() {
|
|
|
|
+ var methodType = $(this).val();
|
|
|
|
+ if (methodType === 'tel' || methodType === 'whatsapp') {
|
|
|
|
+
|
|
|
|
+ $(this).next('.method-input').val('');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
@@ -116,6 +135,36 @@ checkLogin();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
+ function formatPhoneNumber(phone, finalFormat = false) {
|
|
|
|
+ if (!phone) return phone;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ phone = phone.replace(/[^\d\s+]/g, '');
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ phone = phone.trim();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!phone.startsWith('+')) {
|
|
|
|
+
|
|
|
|
+ if (/^\d/.test(phone)) {
|
|
|
|
+ phone = '+' + phone;
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ var firstDigitIndex = phone.search(/\d/);
|
|
|
|
+ if (firstDigitIndex >= 0) {
|
|
|
|
+ phone = '+' + phone.substring(firstDigitIndex);
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ return phone;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return phone;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
function updateMethodFields(methodRow) {
|
|
function updateMethodFields(methodRow) {
|
|
var select = methodRow.find('select.method-select');
|
|
var select = methodRow.find('select.method-select');
|
|
@@ -263,7 +312,7 @@ checkLogin();
|
|
var hasContactMethod = false;
|
|
var hasContactMethod = false;
|
|
var hasAlibabaContact = false;
|
|
var hasAlibabaContact = false;
|
|
var allContactsValid = true;
|
|
var allContactsValid = true;
|
|
- var phoneRegex = /^\+\d{1,4}\s\d{5,}$/;
|
|
+ var phoneRegex = /^\+\d{1,4}\s\d+$/;
|
|
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
|
|
|
|
$('.contact-form').each(function(contactIndex) {
|
|
$('.contact-form').each(function(contactIndex) {
|
|
@@ -296,7 +345,16 @@ checkLogin();
|
|
|
|
|
|
if ((methodType === 'tel' || methodType === 'whatsapp') && methodValue) {
|
|
if ((methodType === 'tel' || methodType === 'whatsapp') && methodValue) {
|
|
if (!phoneRegex.test(methodValue)) {
|
|
if (!phoneRegex.test(methodValue)) {
|
|
- alert("电话格式不正确,请使用以下格式:区号+号码,如 +86 15012345678");
|
|
+
|
|
|
|
+ if (!methodValue.startsWith('+')) {
|
|
|
|
+ alert("电话号码必须以'+'开头");
|
|
|
|
+ } else if (methodValue.indexOf(' ') === -1) {
|
|
|
|
+ alert("区号后必须有空格,例如: +86 15012345678");
|
|
|
|
+ } else if (methodValue.split(' ').length > 2 || methodValue.split(' ')[1].indexOf(' ') !== -1) {
|
|
|
|
+ alert("号码部分不能包含空格");
|
|
|
|
+ } else {
|
|
|
|
+ alert("电话格式不正确,正确格式为: +区号 号码,例如 +86 15012345678");
|
|
|
|
+ }
|
|
$(this).find('input.method-input').focus();
|
|
$(this).find('input.method-input').focus();
|
|
allContactsValid = false;
|
|
allContactsValid = false;
|
|
return false;
|
|
return false;
|