Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ public class Main { /** * Return true if an element/attribute name is a valid NCName (Non Colon Name). * * @param name Non-qualified (no colon) name for an element/attribute. * @return True if an element/attribute name is a valid NCName. */ public static boolean isValidNCName(String name) { if (name == null || name.length() <= 0) return false; if (name.equalsIgnoreCase("XML")) return false; char c = name.charAt(0); if (!Character.isLetter(c) && c != '_') return false; for (int i = 1; i < name.length(); i++) { c = name.charAt(i); if (!Character.isLetter(c) && !Character.isDigit(c) && c != '_' && c != '.' && c != '-') return false; } return true; } }