01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.propertysheet;
11:
12: import org.eclipse.jface.viewers.ICellEditorValidator;
13:
14: /**
15: * Validator for email addresses
16: */
17: public class EmailAddressValidator implements ICellEditorValidator {
18: /**
19: * The <code>EmailAddressValidator</code> implementation of this
20: * <code>ICellEditorValidator</code> method
21: * determines if the value is a valid email address.
22: * (check to see if it is non-null and contains an @)
23: */
24: public String isValid(Object value) {
25: if (value == null) {
26: return MessageUtil.getString("email_address_is_incomplete"); //$NON-NLS-1$
27: }
28: String emailAddress = (String) value;
29: int index = emailAddress.indexOf('@');
30: int length = emailAddress.length();
31: if (index > 0 && index < length) {
32: return null;
33: }
34: return MessageUtil
35: .getString("email_address_does_not_have_a_valid_format"); //$NON-NLS-1$
36: }
37: }
|