javediq_143 Posted July 21, 2009 Share Posted July 21, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.