ฟังก์ชั่นตัดคำหยาบ Javascript
แทนที่คำหยาบที่ไม่ต้องการด้วยข้อความที่กำหนดเอง ใช้ Javascript ครับ
การใช้งาน
<script>
var txt = 'กูจะฆ่ามึง';
alert( ckeckrude( txt ) ); // ---จะฆ่า---
</script>
function ckeckrude( data )
{
//block คำหยาบ และประโยคที่จะนำมาแทนที่
var wordrude = new Array ( "xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","มึง","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","กู","ควย","xxx","xxx","xxx","xxx","ปี้","เหี้ย","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","สัด","เย็ด","หี","xxx","แม่ง","xxx","xxx","แตด" );
var wordchange = '<font style="color:red">--</font>';
for ( n = 0 ; n < wordrude.length ; n++ )
{
pattern = new RegExp( wordrude[n] , "gi" );
data = data.replace( pattern , wordchange );
};
return data;
};
การใช้งาน
<script>
var txt = 'กูจะฆ่ามึง';
alert( ckeckrude( txt ) ); // ---จะฆ่า---
</script>