Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 29. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  regexp - Input is always required?

phpMyEdit Configuration     regexp - Input is always required?
Odoslať novú tému   Odpovedať na tému    
 
philipp     Založený: 19.12.2006   Príspevky: 4  
Príspevok Zaslal: 2007-02-12 07:13
Návrat hore  Odpovedať s citátom     

I'm supposed to do some input validations. On this inputs the user should always be allowed to submit emtpy values. I am using the following regular expression (RegEx):

Kód:
For IP - address
$regexp_IP = '/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/';

For email - address
$regexp_email ='/\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/';

For phonenumber (Examples: 081-3434234, 081-34235, 066-343425)
$regexp_tel = '/[0-9]*-/';

For date:
$regexp_date1 = '/(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])/'; // yyyy-mm-dd

$regexp_date2 = '/(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/'; //dd-mm-yyyy


Now see the example with the telephon number ($regexp_tel)

Kód:
$opts['fdd']['tel'] = array(
     'name'     => 'Tel',
     'select'   => 'T',
     'maxlen'   => 30,
     'sort'     => true
   );
   
$opts['fdd']['tel']['js']['required'] = false;
   
$opts['fdd']['tel']['js']['regexp'] = $regexp_tel
$opts['fdd']['tel']['js']['hint'] = 'Please enter the telephon number in the correct form! (Example: 066-255354)';


It looks like the expressions are correclty, but with all these regex the user is always forced to provide an input , even the value ['required'] is on false?

I also tryed the example from the documentation, which was working, but I can't see where are the differnces to my tries?

Kód:
$opts['fdd']['MBESC_Code']['js']['required'] = false;
$opts['fdd']['MBESC_Code']['js']['regexp'] = '/^[0-9]*$/';
$opts['fdd']['MBESC_Code']['js']['hint']= 'Only numbers are allowed';   
$opts['fdd']['MBESC_Code']['options'] = 'AVCPD';



Help would be appreciated !

 
JammerPro     Založený: 07.12.2006   Príspevky: 33  
Príspevok Zaslal: 2009-10-05 06:51
Návrat hore  Odpovedať s citátom     

SOLVED...

The regexp below will not REQUIRE an entry in the associated fields, but will check any data entered...


//check for valid domain name
'/(^[a-zA-Z0-9._-]{0}$)|(^[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$)/';

//email
'/(^[a-zA-Z0-9._-]{0}$)|(^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$)/';

//zip code
'(/(^\d{0}$)|(^\d{5}$)|(^\d{5}-\d{4}$)/)';

//phone
'(/(^\d{0}$)|(^\d{3}.\d{3}.\d{4}$)/)';

//date
'(/(^\d{0}$)|(^\d{4}\-\d{1,2}\-\d{1,2}$)/)';

Example with phone string:

Kód:

$opts['fdd']['column']['js']['required'] = false;
$opts['fdd']['column']['js']['regexp'] = '(/(^\d{0}$)|(^\d{3}.\d{3}.\d{4}$)/)';//phone - use any of the above strings here to replace the code on this line...
$opts['fdd']['column']['js']['hint']= 'Enter Phone Number with numbers and . only in ###.###.#### format.';   


 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov