|
 |
|
ผิดตรงไหนช่วยดูให้หน่อยค่ะ มันตรวจไม่ผ่านหมดเลย ถึงจะใส่แต่ตัวหนังสือก็ไม่ผ่าน |
|
 |
|
|
 |
 |
|
กรองคำหยาบ + กรองตัวอักษรพิเศษ แต่ใส่ตัวปกติ ก-ฮ a-z ก็ไม่ผ่านติด alert
Code (PHP)
function callAlert() {
Swal.fire({
title: 'คำเตือน',
text: '.. มีอักษรพิเศษ หรือ คำไม่เหมาะสม ..',
icon: 'error',
confirmButtonText: 'ตกลง'
});
}
$('#submit-btn').click(function() {
var validated = true;
var strictWords = ["กู","มึง","สัส","เหี้ย","ควาย"," "]
var firstname = document.getElementById("firstname").value;
var lastname = document.getElementById("lastname").value;
for (var idx in strictWords) {
if (firstname.includes(strictWords[idx]) || lastname.includes(strictWords[idx])) {
validated = false
callAlert()
}
}
let reg = new RegExp(!(/^[a-zA-Zก-ฯ]{5, 20}$/));
if( !reg.test(firstname) || !reg.test(lastname)){
validated = false
callAlert()
}
if (validated) {
$.ajax({
type: 'POST',
url: 'savedata.php',
data: {
firstname: firstname,
lastname: lastname,
},
success: function(response) {
window.location.href = 'savedata.php'
Tag : PHP

|
ประวัติการแก้ไข 2022-05-31 10:58:24 2022-05-31 11:31:23 2022-05-31 11:35:11 2022-05-31 11:37:43
|
 |
 |
 |
 |
Date :
2022-05-31 10:57:30 |
By :
Mirumu |
View :
621 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขยายความ "แต่มันไม่เช็ค ตัวหนังสือ"
พร้อมนำ เฉพาะส่วนที่เกี่ยวข้อง (เช่น HTML, callAlert(), ... ส่วนอื่นที่ไม่เกี่ยวข้องไม่ต้อง เสียเวลาดู) มาแสดงด้วย
|
 |
 |
 |
 |
Date :
2022-05-31 11:23:19 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
function includes() และ callAllert() ทำหน้าที่อะไรครับ
Code (JavaScript)
$('#submit-btn').click(function() {
let firstname= document.getElementById("firstname").value;
let lastname= document.getElementById("lastname").value;
let pat = (/^[a-zA-Zก-ฯ]{5, 20}$/)
let b = !pat.test(firstname) ? 1 : (pat.test(lastname)? true: 2);
if(b) {
let BreakException = {};
try {
[(/กู/),(/มึง/),(/สัส/),(/เหี้ย/),(/ควาย/), (/[\r\n\s\t]/)]
.forEach(function(ele) {
if (ele.test(firstname) || ele.test(lastname)) throw BreakException;
});
} catch (e) {
if (e !== BreakException) {
b=0; alert(e.message); // กรณี error อย่างอื่น
}else b = 3; // error จากการตรวจคำ
}
}
if ( b!==true && b>0) Alert(['', 'ชื่อไม่ถูกต้อง','นามสกุลไม่ถูกต้อง', 'มีคำหยาบ']);
}
|
ประวัติการแก้ไข 2022-05-31 11:45:44
 |
 |
 |
 |
Date :
2022-05-31 11:44:29 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยน if ( b!==true && b>0) Alert(['', 'ชื่อไม่ถูกต้อง','นามสกุลไม่ถูกต้อง', 'มีคำหยาบ']);
เป็น
Code (JavaScript)
if ( b!==true && b>0){
Swal.fire({
title: 'คำเตือน',
text: ['ชื่อไม่ถูกต้อง','นามสกุลไม่ถูกต้อง', 'มีคำไม่เหมาะสม'][b-1],
icon: 'error',
confirmButtonText: 'ตกลง'
});
}
|
ประวัติการแก้ไข 2022-05-31 12:26:17
 |
 |
 |
 |
Date :
2022-05-31 12:24:44 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 5 เขียนโดย : Chaidhanan เมื่อวันที่ 2022-05-31 12:24:44
รายละเอียดของการตอบ ::
ตอนนี้ใช้แบบนี้ค่ะ ตรวจคำหยาบ ตรวจสัญลักษณ์ แต่พิมพ์ชื่อธรรมดา 5 ตัวขึ้นไปก็ยังติด alert อยู่ ขึ้นว่าชื่อไม่ถูกต้องค่ะ
Code (PHP)
$('#submit-btn').click(function() {
let firstname = document.getElementById("firstname").value;
let lastname = document.getElementById("lastname").value;
let pat = (/^[a-zA-Zก-ฯ]{5, 20}$/)
let b = !pat.test(firstname) ? 1 : (pat.test(lastname)? true: 2);
if(b) {
let BreakException = {};
try {
[(/กู/),(/มึง/),(/สัส/),(/เหี้ย/),(/ควาย/), (/[\r\n\s\t]/)]
.forEach(function(ele) {
if (ele.test(firstname) || ele.test(lastname)) throw BreakException;
});
} catch (e) {
if (e !== BreakException) {
b=0; alert(e.message); // กรณี error อย่างอื่น
}else b = 3; // error จากการตรวจคำ
}
}
if ( b!==true && b>0){
Swal.fire({
title: 'คำเตือน',
text: ['ชื่อไม่ถูกต้อง','นามสกุลไม่ถูกต้อง', 'มีคำไม่เหมาะสม'][b-1],
icon: 'error',
confirmButtonText: 'ตกลง'
});
}
if (validated) {
$.ajax({
type: 'POST',
url: 'savedata.php',
data: {
firstname: firstname,
lastname: lastname,
},
success: function(response) {
window.location.href = 'savedata.php'
}
});
}
})
|
ประวัติการแก้ไข 2022-05-31 12:38:09 2022-05-31 12:38:39 2022-05-31 12:44:43
 |
 |
 |
 |
Date :
2022-05-31 12:37:06 |
By :
Mirumu |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่วิเคราะห์เลยนะครับ กีอปอย่างเดียวเลย
ผมไม่ใช้ ตัวแปร validated แล้ว ก็ยังใช้อยู่อีก
และ
Code (JavaScript)
if( con ) {
// true do something
}else{
// false do something
}
ใช้ให้เป็น ถ้ายังใช้ไม่เป็น อย่าเขียนโปรแกรมเลยครับ พื้นฐาน ทางเลือกของภาษาคอมฯ ต้องเป็น
และก็หัดวิเคราะห์โปรแกรมด้วย ถ้าไม่วิเคราะห์โปรแกรมจะเป็น นักคอมฯนักคณิตศาสตร์ได้ยังไง
Code (JavaScript)
$('#submit-btn').click(function() {
let firstname = document.getElementById("firstname").value;
let lastname = document.getElementById("lastname").value;
let pat = (/^[a-zA-Zก-ฯ]{5, 20}$/);
let b = !pat.test(firstname) ? 1 : (pat.test(lastname)? true: 2);
if(b===true) {
let BreakException = {};
try {
[(/กู/),(/มึง/),(/สัส/),(/เหี้ย/),(/ควาย/), (/[\r\n\s\t]/)]
.forEach(function(ele) {
if (ele.test(firstname) || ele.test(lastname)) throw BreakException;
});
} catch (e) {
if (e !== BreakException) {
b=0; alert(e.message); // กรณี error อย่างอื่น
}else b = 3; // error จากการตรวจคำ
}
}
if ( b===true){
$.ajax({
type: 'POST',
url: 'savedata.php',
data: {
firstname: firstname,
lastname: lastname,
},
success: function(response) {
window.location.href = 'savedata.php'
}
});
}else if(b>0){
Swal.fire({
title: 'คำเตือน',
text: ['ชื่อไม่ถูกต้อง','นามสกุลไม่ถูกต้อง', 'มีคำไม่เหมาะสม'][b-1],
icon: 'error',
confirmButtonText: 'ตกลง'
});
}
});
|
 |
 |
 |
 |
Date :
2022-05-31 13:09:18 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
let pat = (/^[a-zA-Zก-ฯ]{5, 20}+$/);
ไปก๊อปมาจากไหนล่ะ?
เขียนก็ผิดอีก
เอาจริงๆตัวแพทเทิร์นใช้แบบนี้ก็ได้ มี i สำหรับ case insensitive แล้วก็ใน {n,n} ต้องไม่มีเว้นวรรค นี่ก็ก๊อปมาผิดมันจะทำงานได้ไงล่ะ?
Code (JavaScript)
let pattern = /^[a-zก-ฯ]{5,20}$/gmi;
|
 |
 |
 |
 |
Date :
2022-05-31 14:17:58 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|