Greetings to all who have entered

Actually there are a million regulars on the Internet. Suit so-so. Pristavte you need to check the 'name'. Well, let's say There must be at least 2 characters in English.

  1. The person wanted to enter - 'my', and entered - 'm.y'. Regular eats, but will not find anything. Is it possible to get only letters at the output in a variable? and check them out 2 or more? ('my' .. user friendly so to speak)

  2. Well, or take an email. It's more fun. Suppose a person wants to enter email123@site.ru, and entered - email123@siYte.ru. I don `t know the worker is an email or not. And to hell with him. Yes, and the user is not necessarily a cracker. But let's say you need to forgive a fool, and get a variable with a processed email at the output, and check it out already.

those. how to do:

переменная -> выкидываем_лишнее -> if(регулярка ?){все_ок}else{что_то_не_так} ? 
  • eight
    you would sleep and forget this thought, well, read about regular expressions ... you won’t guess at all :) - zb '
  • > variable -> throwing out ... unnecessary ... Or according to a different scheme:> the user types the text -> every input character (JS) is checked -> if (something_sufficient) alert ("Houston! We have problems!"); - Deonis
  • Data is not always entered. Sometimes obtained from another place. So that JS does not roll. Here's how you need to filter the characters one by one - frank
  • 2
    @frank, the game is not worth the candle. Nine times, you clean the data correctly, but because, as @eicto correctly noted, “you don’t know everything, ” for the tenth time, delete what was not subject to deletion. And most likely, that your mistakes in this will be more than those users who have been sealed. - Deonis
  • one
    Name? At least two characters in English? Ha ha ha . - VladD

2 answers 2

Um ... if anyone simplifies this design - I will be grateful. In general, the essence is this: we take the value at the input, skip through the replacement. We get the output value consisting of those characters that are needed. Well, then torment the variable with regular check

  • are you looking for it?

     $zamena = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ@. "; $input = preg_replace('/[^'.preg_quote($zamena).']/', '', $input); 
  • 2
    Read about character classes in regular expressions. - ReinRaus

Yes, you are right, users will sooner or later make a mistake when entering data. Therefore it is necessary to use validators. Below are a few recommendations for correcting data entry validation.

  • Use a mask for the components that the user fills with data.
  • If you cannot use a mask, then at least catch and block all unwanted characters, as well as set the upper and lower limit of the length of the entered text. For example: email123@site.ru => email123@siYte.ru errors should not occur if you set the boundaries of length 3-256, check for the presence of the "@" symbol and allow you to enter only letters of the Latin alphabet, numbers 0-9 and some ASCII characters (33, 35–39, 42, 43, 45, 47, 61, 63, 64, 94–96, 123–126) and a point.
  • When developing a multilingual web portal, consider regional standards, such as time formatting and working with monetary units.
  • Do not try to replace the drop-down lists with text input fields. Very often I see this error. If the drop-down list contains a huge number of options, then you need to implement input with auto-completion and search function.

Naturally, we are talking about the front-end. Our task here is to make the user's work as comfortable as possible and minimize the number of errors. For security reasons, in the implementation of the back-end it is necessary to create a repeated, more stringent check of the data received by the server.


About trying to fix user errors yourself. This idea is fundamentally wrong and irrational. It is difficult to implement (you need to use AI, dictionaries, and many other things), you can encounter even more problems when implementing it, and generally allowing you to enter anything you want, you will only confuse it.