Jump to content

Recommended Posts

Hi All,

I'm developing my first CMS system and got stuck in a section where the Admin can ENTER NEW Records. I want to validate the input using Regular Exp but not getting thru it as I'm totally new to this. Though I've written Reg Exp, which is working fine; to my assumption, I think the codes are not good as they are very lengthy.

 

Below are the variation of input which the Admin can enter. I need an expression to validate these given types:

NOTE:word denote single word of any length of char incl only a-z/A-Z and period

 

[*]word

[*]word word

[*]word word word    No Code written for this 

[*]Char(s). word

[*]Char(s). word word    No Code written for this

[*]Char. Char. word

 

The code which I've written are:



function valid_alpha_nm($str)
{
      //VALIDATE FIRST TYPE
if(eregi('^[a-zA-Z]+$', $str))
{
return true;
}
     
      //VALIDATE SECOND TYPE
if(eregi('^[a-zA-Z]+[[:space:]]{1}[a-zA-Z]+$', $str)) 
{
return true;
}

      //VALIDATE FOURTH TYPE
if(eregi('^[a-zA-Z]+[\.]{1}[[:space:]]{1}[a-zA-Z]+$', $str))
{
return true;
}

      //VALIDATE SIXTH TYPE
if(eregi('^[a-zA-Z]+[\.]{1}[[:space:]]{1}[a-zA-Z]{1}[\.]{1}[[:space:]]{1}[a-zA-Z]+$', $str))
{
return true;
}
return false;
}

 

Can anyone help me to make it cut short or write a better expression which can validate the above given types of input.

 

Please help me soon.

 

Thanks & Regards,

Javed

Link to comment
https://forums.phpfreaks.com/topic/166762-cut-short-regular-expression/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.