Filtering words in text string

0

I'm needing a functional solution for a system I'm doing.

I need to block the textarea field record if it contains some words in the string, eg:

This is a brief description of my profile, my phone 33 3333-3333, my email: [email protected], and my site: www.mysite.com or myite.com

I want to block, that is, not allow these items in the string, I do not want any type of contact, neither phone, nor email, nor website, nor facebook nor any kind of social network.

It can be a solution in Javascript or pure PHP, which is as simple and objective as possible.

I'm waiting for a return from you!

Att

Alisson maciel

    
asked by anonymous 13.10.2017 / 19:40

1 answer

0

There are a few ways to do this, a basic way would be.

$('textarea').keyup(function(){
  var texto = $(this).val()
  var email = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2,3}/
  var telefone = /^(\(11\) [9][0-9]{4}-[0-9]{4})|(\(1[2-9]\) [5-9][0-9]{3}-[0-9]{4})|(\([2-9][1-9]\) [5-9][0-9]{3}-[0-9]{4})$/

  texto = texto.replace(email, 'xxxxxxxxxx')
  texto = texto.replace(telefone, 'xxxxxxx')
  
  $('.result').text(texto)
})
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title></title>
</head>
<body>
  <textarea></textarea>
  <div class="result"></div>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script></body></html>

Ididatestbytypingintextarea,"Hi my phone is" , and the result was: "Hi my xxxxxxxxxx is"     

13.10.2017 / 20:09