\$\begingroup\$
\$\endgroup\$
1
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
*/
-
\$\begingroup\$ generic function (should be renamed to checkpattern) should not be setting the response. \$\endgroup\$NRS– NRS2011年11月16日 19:01:45 +00:00Commented Nov 16, 2011 at 19:01
1 Answer 1
\$\begingroup\$
\$\endgroup\$
1
Few additions
1) First get some unit tests in
2) I would do something like this http://jsfiddle.net/Brw4W/1/
-
\$\begingroup\$ Didn't get you . What is the best practice \$\endgroup\$NRS– NRS2011年11月18日 14:18:45 +00:00Commented Nov 18, 2011 at 14:18
default