Ext


Go Back   Ext JS Forums > Ext General Forums > Ext: Examples and Extras

Reply
 
Thread Tools
  #1  
Old 04-06-2007, 12:43 PM
vtswingkid vtswingkid is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: Virginia, USA
Posts: 465
vtswingkid is on a distinguished road
Thumbs up More VTypes!

In the spirit of opensource here is some code to expand on the VTypes. I'll add more as I need them.

Ext.form.VTypes["hostnameVal1"] = /^[a-zA-Z][-.a-zA-Z0-9]{0,254}$/;
Ext.form.VTypes["hostnameVal2"] = /^[a-zA-Z]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9]){0,1}([.][a-zA-Z]([-a-zA-Z0-9]{0,61}[a-zA-Z0-9]){0,1}){0,}$/;
Ext.form.VTypes["ipVal"] = /^([1-9][0-9]{0,1}|1[013-9][0-9]|12[0-689]|2[01][0-9]|22[0-3])([.]([1-9]{0,1}[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){2}[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-4])$/;
Ext.form.VTypes["netmaskVal"] = /^(128|192|224|24[08]|25[245].0.0.0)|(255.(0|128|192|224|24[08]|25[245]).0.0)|(255.255.(0|128|192|224|24[08]|25[245]).0)|(255.255.255.(0|128|192|224|24[08]|252))$/;
Ext.form.VTypes["portVal"] = /^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;
Ext.form.VTypes["multicastVal"] = /^((22[5-9]|23[0-9])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3})|(224[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])){2})|(224[.]0[.]([1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.](0|[1-9][0-9]{0,1}|1[0-9]{2}|2[0-4][0-9]|25[0-5])))$/;
Ext.form.VTypes["usernameVal"] = /^[a-zA-Z][-_.a-zA-Z0-9]{0,30}$/;
Ext.form.VTypes["passwordVal1"] = /^.{6,31}$/;
Ext.form.VTypes["passwordVal2"] = /[^a-zA-Z].*[^a-zA-Z]/;
Ext.form.VTypes["hostname"]=function(v){
 if(!Ext.form.VTypes["hostnameVal1"].test(v)){
  Ext.form.VTypes["hostnameText"]="Must begin with a letter and not exceed 255 characters"
  return false;
 }
 Ext.form.VTypes["hostnameText"]="L[.L][.L][.L][...] where L begins with a letter, ends with a letter or number, and does not exceed 63 characters";
 return Ext.form.VTypes["hostnameVal2"].test(v);
}
Ext.form.VTypes["hostnameText"]="Invalid Hostname"
Ext.form.VTypes["hostnameMask"]=/[-.a-zA-Z0-9]/;
Ext.form.VTypes["ip"]=function(v){
 return Ext.form.VTypes["ipVal"].test(v);
}
Ext.form.VTypes["ipText"]="1.0.0.1 - 223.255.255.254 excluding 127.x.x.x"
Ext.form.VTypes["ipMask"]=/[.0-9]/;
Ext.form.VTypes["netmask"]=function(v){
 return Ext.form.VTypes["netmaskVal"].test(v);
}
Ext.form.VTypes["netmaskText"]="128.0.0.0 - 255.255.255.252"
Ext.form.VTypes["netmaskMask"]=/[.0-9]/;
Ext.form.VTypes["port"]=function(v){
 return Ext.form.VTypes["portVal"].test(v);
}
Ext.form.VTypes["portText"]="0 - 65535"
Ext.form.VTypes["portMask"]=/[0-9]/;
Ext.form.VTypes["multicast"]=function(v){
 return Ext.form.VTypes["multicastVal"].test(v);
}
Ext.form.VTypes["multicastText"]="224.0.1.0 - 239.255.255.255"
Ext.form.VTypes["multicastMask"]=/[.0-9]/;
Ext.form.VTypes["username"]=function(v){
 return Ext.form.VTypes["usernameVal"].test(v);
}
Ext.form.VTypes["usernameText"]="Username must begin with a letter and cannot exceed 255 characters"
Ext.form.VTypes["usernameMask"]=/[-_.a-zA-Z0-9]/;
Ext.form.VTypes["password"]=function(v){
 if(!Ext.form.VTypes["passwordVal1"].test(v)){
  Ext.form.VTypes["passwordText"]="Password length must be 6 to 31 characters long";
  return false;
 }
 Ext.form.VTypes["passwordText"]="Password must include atleast 2 numbers or symbols";
 return Ext.form.VTypes["passwordVal2"].test(v);
}
Ext.form.VTypes["passwordText"]="Invalid Password"
Ext.form.VTypes["passwordMask"]=/./;
Reply With Quote
  #2  
Old 04-06-2007, 12:51 PM
mikegiddens's Avatar
mikegiddens mikegiddens is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: Baton Rouge, Louisiana
Posts: 260
mikegiddens is on a distinguished road
Send a message via Skype™ to mikegiddens
Default

This looks great! I love you regex people.
__________________
Mike Giddens
=======================
Opportunity is missed by most people because it is dressed in overalls and looks like work - Thomas Edison
Reply With Quote
  #3  
Old 04-06-2007, 12:57 PM
vtswingkid vtswingkid is offline
Ext JS Premium Member
 
Join Date: Mar 2007
Location: Virginia, USA
Posts: 465
vtswingkid is on a distinguished road
Default

I am just getting into it. Am already starting to think it is more fun than sudoku!
Reply With Quote
  #4  
Old 04-06-2007, 01:05 PM
jack.slocum's Avatar
jack.slocum jack.slocum is offline
Ext JS - Development Team
 
Join Date: Mar 2007
Posts: 6,941
jack.slocum is on a distinguished road
Default

Quote:
Originally Posted by vtswingkid View Post
I am just getting into it. Am already starting to think it is more fun than sudoku!
LOL. Now that is funny.
__________________
Jack Slocum
Ext JS - Core Development Team
jack@extjs.com
Reply With Quote
  #5  
Old 04-25-2007, 02:54 PM
Nullity Nullity is offline
Ext User
 
Join Date: Mar 2007
Posts: 170
Nullity is on a distinguished road
Default

Here is another regex for testing phone numbers (US phone numbers, it could be adapted easily for other countries):

Ext.form.VTypes["phone"] = /^(\d{3}[-]?){1,2}(\d{4})$/;
Ext.form.VTypes["phoneMask"] = /[\d-]/;
Ext.form.VTypes["phoneText"] = 'Not a valid phone number.  Must be in the format 123-4567 or 123-456-7890 (dashes optional)';
EDIT: added the mask regex
Reply With Quote
  #6  
Old 04-27-2007, 08:19 AM
alien3d alien3d is offline
Ext User
 
Join Date: Mar 2007
Posts: 126
alien3d is on a distinguished road
Default numeric only value

i also add just for numeric only value.But it wouldn't run on ie7.Any body had try it and code it ?Firefox it will allow numeric value from the above qwert keyboard but left keyboard fail.
Any idea?
Reply With Quote
  #7  
Old 04-27-2007, 09:37 AM
Nullity Nullity is offline
Ext User
 
Join Date: Mar 2007
Posts: 170
Nullity is on a distinguished road
Default

If you want to be able to enter only numbers, you can use either
/\d/
or
/[0-9]/
Is that what you are asking? I hope I am understanding you correctly. If you are referring to my phone number regex not working in Internet Explorer, try this one instead:
/^([0-9]{3}[-]?){1,2}([0-9]{4})$/
Reply With Quote
  #8  
Old 04-27-2007, 02:57 PM
Nullity Nullity is offline
Ext User
 
Join Date: Mar 2007
Posts: 170
Nullity is on a distinguished road
Default

Here are two more. One for US Dollars:

Ext.form.VTypes["dollar"] = /^[\$]?[\d]*(.[\d]{2})?$/;
Ext.form.VTypes["dollarMask"] = /[\d\$.]/;
Ext.form.VTypes["dollarText"] = 'Not a valid dollar amount.  Must be in the format "$123.45" ($ symbol and cents optional).';
and one for time:
Ext.form.VTypes["time"] = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Ext.form.VTypes["timeMask"] = /[\d\s:amp]/i;
Ext.form.VTypes["timeText"] = 'Not a valid time.  Must be in the format "12:34 PM".';
EDIT: added the mask regex's
Reply With Quote
  #9  
Old 04-28-2007, 11:48 PM
alien3d alien3d is offline
Ext User
 
Join Date: Mar 2007
Posts: 126
alien3d is on a distinguished road
Default vtype

Thanks for the code.I will try it
Reply With Quote
  #10  
Old 04-29-2007, 09:10 PM
monday monday is offline
Ext User
 
Join Date: Apr 2007
Location: CHINA
Posts: 2
monday is on a distinguished road
Send a message via MSN to monday
Default

This looks great! Thanks for the code.
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 12:57 PM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.