1
\$\begingroup\$

EDIT:

Function is returnted to JClass Text. Prototypes hold non instance members (statics). No privacy. Privacy requires self executing methods.

var Text = function( form_name ) 
{
 this.text_array = document.forms[form_name].elements;
};
Text.prototype.patterns = 
{
 prefix_url: /^http:\/\//,
 url: /^.{1,2048}$/,
 tweet: /^.{1,40}$/, 
 title: /^.{1,32}$/, 
 name: /^.{1,64}$/, 
 email: /^.{1,64}@.{1,255}$/,
 pass: /^.{6,20}$/
};
Text.prototype.pattern = function( type ) 
{
 return this.patterns[type].exec( this.text_array[type].value );
};
Text.prototype.patternAdd = function( type ) 
{
 return this.patterns[type].exec( this.text_array.url.value );
};
Text.prototype.same = function() 
{
 return ( (this.text_array.email.value) === (this.text_array.email1.value) );
};
Text.prototype.emptyUser = function() 
{
 var element;
 for ( element in this.text_array )
 {
 if( this.text_array[element].value === '' ) 
 {
 return 0;
 }
 }
 return 1;
};
/**
 * Text End
 */
asked Nov 16, 2011 at 5:13
\$\endgroup\$
1
  • \$\begingroup\$ generic function (should be renamed to checkpattern) should not be setting the response. \$\endgroup\$ Commented Nov 16, 2011 at 19:01

1 Answer 1

1
\$\begingroup\$

Few additions

1) First get some unit tests in

2) I would do something like this http://jsfiddle.net/Brw4W/1/

answered Nov 17, 2011 at 9:32
\$\endgroup\$
1
  • \$\begingroup\$ Didn't get you . What is the best practice \$\endgroup\$ Commented Nov 18, 2011 at 14:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.