Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Feedback on: Addressing Form Field Validation with Regular Expressions and JavaScript 1.2, September 06, 2001 at 15:11:22:

You are here: irt.org | About | Feedback | 3137 [ previous next ]

Feedback on:
Addressing Form Field Validation with Regular Expressions and JavaScript 1.2

Sent by
frank koenen on September 06, 2001 at 15:11:22:

Worth:
Worth reading

Comments:
Jason,

I saw your article at tech.irt.org, http://tech.irt.org/articles/js049/source.htm
Your article was very informative, the best of the articles I saw in a quick search of google on the
topic.

I am experiencing a bit of a problem with regexp however, in Internet Explorer 5.5. The code
below works in Netscape just fine. However, IE only processes the simple regexp expressions.

Can you test run and help explain why the "^" and "$" chars only work in NS not IE?

Your input would be greatly appreciated and it might serve as a good
future article too.


Thanks. Frank Koenen
=======================================================================

<html><head>
<script language='javascript1.2'>
cmp00008_dnames=new Array('_larry','_hx','_bad');
cmp00008_dvalues=new Array('Larry Smith','History is good.','Bad is Bad');

function cmp00008_dictionaryobject(){
this.names = cmp00008_dnames;
this.values = cmp00008_dnames;
this.expandwords = cmp00008_dictionaryexpandword;
}

function cmp00008_dictionaryexpandword(formname,fieldname){
//alert('hello from cmp00008_dictionaryexpandword formname='+formname+' fieldname='+fieldname);
var Obj=eval('document.'+formname+'.'+fieldname);
var Words=Obj.value;
var re='',i,m;
for(i=0;i<cmp00008_dnames.length;i++){
m=new RegExp(cmp00008_dnames[i]+' |'+cmp00008_dnames[i]+'\n| '+cmp00008_dnames[i]+'$|^'+cmp00008_dnames[i]+'$','g');
if(m.test(Words)){
re=m.compile(' '+cmp00008_dnames[i]+' ','g');Words=Words.replace(re,' '+cmp00008_dvalues[i]+' ');
re=m.compile(' '+cmp00008_dnames[i]+' ','g');Words=Words.replace(re,' '+cmp00008_dvalues[i]+' ');
re=m.compile('^'+cmp00008_dnames[i]+' ','g');Words=Words.replace(re,cmp00008_dvalues[i]+' ');
Words=Words.replace(cmp00008_dnames[i]+'\n',cmp00008_dvalues[i]+'\n');
Words=Words.replace(cmp00008_dnames[i]+'$',cmp00008_dvalues[i]);
Words=Words.replace('^'+cmp00008_dnames[i]+'$',cmp00008_dvalues[i]);
}
}
if(re!='')Obj.value=Words;
}

cmp00008_dictionary = new cmp00008_dictionaryobject();

</head>

// to call it<br>
<a href=javascript:void(0) onclick=cmp00008_dictionary.expandwords('ff','ta')>here</a>
<br>

// the form<br>
<form name="ff" method="post">
<textarea rows=100 cols=200 name="ta">what a _larry
No Yes _larry _larry _larry _hx hello
_larry x
_hx
This line larry_larry alone! x_hx too.
_larry _hx _larry</textarea>
<input type='hidden' name="cmp00008editmydictcmp000083b96945133498">
</form></html>



Other feedback on 'Addressing Form Field Validation with Regular Expressions and JavaScript 1.2' - show all

©2018 Martin Webb