Text string word filtering

Asked

Viewed 78 times

0

I need a working solution for a system I’m making.

I need to block textarea field registration if it contains a few words in the string, example:

This is a brief description about my profile, my phone 33 3333-3333, my email: [email protected], and my website: www.meusite.com or meusite.com

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

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

I await your return!

Att

Alisson Maciel

  • 1
  • Have you tried anything? Do you have any idea how you can do it at least? What do you know about regular expressions?

  • Yes, I know a little bit of regular expressions I’m even using here, some validations and working, except that my main interest is to block the email and domain in the string. And this I can’t, I’m using a function with strpos, I’m using a function I could, to validate the field using the array_merge and the array_intersect, and etc. But I couldn’t block URL and E-mail in the string

1 answer

0


There are some 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>

I did a test by typing in textarea, "Hi my phone is", and the result was: "Hi my xxxxxxx is"

  • I get it, I find it interesting, only I need to check if what is typed is an email, phone or a domain, agree? So I need someone else who can collaborate with this code of yours, to solve this question with us.

  • Why not try to do a function that clears characters from the string using SQL Injection ?

  • @Alissonmaciel the idea here is to give you a basis and you from it. However, I edited my answer, you can test by placing an email, I put [email protected], and he puts xxxxxxx in place, in question of the telephone, +99 (99) 9999-9999, and the same thing happens. Remembering that this is a basic form, the interesting thing is that you modify according to your need.

  • @Rafaelaugusto I know understand Rafael, so I informed that its function is very interesting, only it is not yet what I need, because what I really need, is in my doubt, and what you posted still does not answer, but has an implementation.

  • kkk, I didn’t even see your new change, it got too good I’ll test

  • how do I concatenate several phones with jquery? Example:

  • vc has created there the function that the user needs to put the +55,. suppose it does not put, just enter the ddd and the number, or just the numbers. But I don’t want to rule out the existing regular expression. I want her to continue, and I want to add more of these, but on the same variable phone, so I don’t have to ride several variables

  • @Alissonmaciel I edited the answer

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.