001 // Copyright (c) 2001 Hursh Jain (http://www.mollypages.org)
002 // The Molly framework is freely distributable under the terms of an
003 // MIT-style license. For details, see the molly pages web site at:
004 // http://www.mollypages.org/. Use, modify, have fun !
005
006 package fc.web.forms;
007
008 import javax.servlet.*;
009 import javax.servlet.http.*;
010 import java.io.*;
011 import java.util.*;
012 import java.util.regex.*;
013
014 import fc.jdbc.*;
015 import fc.io.*;
016 import fc.util.*;
017
018 /**
019 Validates two text input boxes to see if they are the same. (this could
020 be a text box for say email and a second text box to confirm the email).
021 <p>
022 Note, other rules such as required length, characters etc., are not
023 checked by this validator. Add a {@link VText} to each password field for
024 that purupose.
025
026 @author hursh jain
027 **/
028 public final class VSameText extends FormValidator
029 {
030 Text field_one;
031 Text field_two;
032
033 /**
034 @param field_one the first text box
035 @param field_two the second text box
036 **/
037 public VSameText(Form f, String name, String errorMessage,
038 Text field_one, Text field_two)
039 {
040 super(f, name, errorMessage);
041 Argcheck.notnull(field_one, "parm field_one was null");
042 Argcheck.notnull(field_two, "parm field_two was null");
043 this.field_one = field_one;
044 this.field_two = field_two;
045 }
046
047 public boolean validate(FormData fd, HttpServletRequest req)
048 {
049 String one = field_one.getValue(fd);
050 String two = field_two.getValue(fd);
051 boolean result = false;
052
053 if ( one != null && one.equals(two) )
054 result = true;
055
056 return result;
057 }
058
059 } //~class VSameText
060