Welcome Guest, Not a member yet? Register   Sign In
How to disable/enable keys
#7

(This post was last modified: 02-14-2021, 10:38 AM by christaliise.)

(02-12-2021, 08:26 AM)brianjamestorr Wrote:
(02-11-2021, 12:23 PM)christaliise Wrote:
(02-10-2021, 01:33 AM)brianjamestorr Wrote: You can use regex and disable input for those characters you don't allow.

Here is example Code

In regex string you can put or remove characters you don't want to allow like in here, allowed characters are:
- letters from a-z (lowercase)
- letters from A-Z (uppercase)
- numbers from 0-9
- space
- dot
- @ sign
- #sign
- $ sign
- % sign
- & sign
PHP Code:
[a-zA-Z0-.@#$%&] 

Thanks @brianjamestorr but is that Javascript, PHP or other?

Can you give an example of some coding?


Well depends what you want to have, block user to enter character when typing or when form is submitted.

With javascript you can block user enters letters in input, but this is not really secure, so you can do it in javascript and also in php just to be safe.

Using regex with built in function for form validation 
PHP Code:
$this->form_validation->set_rules('''''regex_match[/a-zA-Z0-9 .@#$%&/]'); 

then message you will get if character is not allowed is "The {field} field is not in correct format.", but you can change that message.



Thanks @brianjamestorr - I think it is prudent to have both, frontend & backend. In the meantime Im focusing on the form_validation & only one text box (Length). I have added your snippet of code (but allowing only 0-9 .) in addition to an existing form_validation line as below, but I get the following error.

Message: Call to undefined function length()

PHP Code:
$config = array( //This line is existing
array('field' => 'length''label' => 'Length''rules' => 'required''errors' => array( 'required' => 'Provide%s')), //This line is existing
array('field' => 'length' ('''''regex_match[/0-9./]'); //This line obviously needs to be defined
$this->form_validation->set_rules($config); //This line is existing 

Can you advise what is needed to define the function?

As a matter of interest will that allow backspace?
Reply


Messages In This Thread
How to disable/enable keys - by christaliise - 02-07-2021, 05:27 AM
RE: How to disable/enable keys - by paliz - 02-07-2021, 12:14 PM
RE: How to disable/enable keys - by christaliise - 02-07-2021, 02:43 PM
RE: How to disable/enable keys - by christaliise - 02-11-2021, 12:23 PM
RE: How to disable/enable keys - by christaliise - 02-14-2021, 10:35 AM
RE: How to disable/enable keys - by christaliise - 02-18-2021, 07:15 AM
RE: How to disable/enable keys - by christaliise - 02-26-2021, 05:03 AM
RE: How to disable/enable keys - by christaliise - 02-27-2021, 06:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB