ฟังก์ชั่นตัดคำหยาบ Javascript

แทนที่คำหยาบที่ไม่ต้องการด้วยข้อความที่กำหนดเอง ใช้ Javascript ครับ

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","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 = 'xxxจะฆ่าxxx';
  alert( ckeckrude( txt ) ); // ---จะฆ่า---
</script>

ผู้เขียน Goragod โพสต์เมื่อ 01 เม.ย. 2551 เปิดดู 6,387 ป้ายกำกับ Javascript

เรื่องที่เกี่ยวข้อง

^