- 博客(0)
- 资源 (11)
- 收藏
- 关注
特殊字符前面加斜线的代码
char[] specialChars = {'(',')','*','.'};
String test = "()*.";
String result = "";
char temp;
boolean isExist = false;
for (int i = 0; i < test.length(); i++) {
temp = test.charAt(i);
isExist = false;
for (int j = 0; j < specialChars.length; j++) {
if (temp == specialChars[j]) {
isExist = true;
break;
}
}
result += ((isExist ? "\\" : "")+temp);
}
System.out.println(result);
2010-11-08
密码大写小写数字重复
function validate(str){
var illegalChars = ['*','-'];//指定的特殊字符写在这个数组里面,个数不限。
str = str.value;
var numberCount = 0;
var upperCaseCount = 0;
var lowerCaseCount = 0;
var otherCharCount = 0;
var numberIndex = 0;
var upperCaseIndex = 0;
var lowerCaseIndex = 0;
var otherCharIndex = 0;
var temp;
for (var i = 0; i < str.length; i++) {
temp = str.charAt(i);
for(var j = 0; j < illegalChars.length; j++){
if(temp == illegalChars[j]){
return false;
}
}
temp = temp.charCodeAt();
if (temp >= 48 && temp <= 57) {
numberIndex = i;
numberCount++;
}else if(temp >= 65 && temp <= 90){
upperCaseIndex = i;
upperCaseCount++;
}else if(temp >= 97 && temp <= 122){
lowerCaseIndex = i;
lowerCaseCount++;
}else{
otherCharIndex = i;
otherCharCount++;
}
}
if (numberCount == 0 || (numberCount == 1 && (numberIndex == 0 || numberIndex == str.length-1 ))) {
return false;
}
if (upperCaseCount == 0 || (upperCaseCount == 1 && (upperCaseIndex == 0 || upperCaseIndex == str.length-1 ))) {
return false;
}
if (lowerCaseCount == 0 || (lowerCaseCount == 1 && (lowerCaseIndex == 0 || lowerCaseIndex == str.length-1 ))) {
return false;
}
if (otherCharCount == 0 || (otherCharCount == 1 && (otherCharIndex == 0 || otherCharIndex == str.length-1 ))) {
return false;
}
var result;
for(var i=0;i<str.length/2;i++){
if(i==0 && str.length%(i+1)!=0){
continue;
}
result = replaceAll(str,str.substring(0,i+1),"");
if(result.length == 0){
return false;
}
}
return true;
}
function replaceAll(str,oldStr,newStr){
for(var i=0;i<str.length;i++){
str = str.replace(oldStr,newStr);
}
return str;
}
2010-10-29
指定特殊字符不能使用
function validate(str){
var illegalChars = ['*','-'];//指定的特殊字符写在这个数组里面,个数不限。
str = str.value;
var numberCount = 0;
var upperCaseCount = 0;
var lowerCaseCount = 0;
var otherCharCount = 0;
var numberIndex = 0;
var upperCaseIndex = 0;
var lowerCaseIndex = 0;
var otherCharIndex = 0;
var temp;
for (var i = 0; i < str.length; i++) {
temp = str.charAt(i);
for(var j = 0; j < illegalChars.length; j++){
if(temp == illegalChars[j]){
return false;
}
}
temp = temp.charCodeAt();
if (temp >= 48 && temp <= 57) {
numberIndex = i;
numberCount++;
}else if(temp >= 65 && temp <= 90){
upperCaseIndex = i;
upperCaseCount++;
}else if(temp >= 97 && temp <= 122){
lowerCaseIndex = i;
lowerCaseCount++;
}else{
otherCharIndex = i;
otherCharCount++;
}
}
if (numberCount == 0 || (numberCount == 1 && (numberIndex == 0 || numberIndex == str.length-1 ))) {
return false;
}
if (upperCaseCount == 0 || (upperCaseCount == 1 && (upperCaseIndex == 0 || upperCaseIndex == str.length-1 ))) {
return false;
}
if (lowerCaseCount == 0 || (lowerCaseCount == 1 && (lowerCaseIndex == 0 || lowerCaseIndex == str.length-1 ))) {
return false;
}
if (otherCharCount == 0 || (otherCharCount == 1 && (otherCharIndex == 0 || otherCharIndex == str.length-1 ))) {
return false;
}
return true;
}
2010-10-29
js 校验密码重复的代码
function validate(str){
str = str.value;
var reg = new RegExp("^\\w{8,31}$");
if(reg.test(str)){
for(var i=0;i<str.length/2;i++){
if(str.replace(str.substring(0,i+1), "").length==0){
return false;
}
}
return true;
}
return false;
}
2010-10-28
java script 校验验证码
文件里面的是错的,用这个。
function validate(str){
str = str.value;
var numberCount = 0;
var upperCaseCount = 0;
var lowerCaseCount = 0;
var otherCharCount = 0;
var numberIndex = 0;
var upperCaseIndex = 0;
var lowerCaseIndex = 0;
var otherCharIndex = 0;
for (var i = 0; i < str.length; i++) {
var temp = str.charAt(i).charCodeAt();
if (temp >= 48 && temp <= 57) {
numberIndex = i;
numberCount++;
}else if(temp >= 65 && temp <= 90){
upperCaseIndex = i;
upperCaseCount++;
}else if(temp >= 97 && temp <= 122){
lowerCaseIndex = i;
lowerCaseCount++;
}else{
otherCharIndex = i;
otherCharCount++;
}
}
if (numberCount == 0 || (numberCount == 1 && (numberIndex == 0 || numberIndex == str.length-1 ))) {
return false;
}
if (upperCaseCount == 0 || (upperCaseCount == 1 && (upperCaseIndex == 0 || upperCaseIndex == str.length-1 ))) {
return false;
}
if (lowerCaseCount == 0 || (lowerCaseCount == 1 && (lowerCaseIndex == 0 || lowerCaseIndex == str.length-1 ))) {
return false;
}
if (otherCharCount == 0 || (otherCharCount == 1 && (otherCharIndex == 0 || otherCharIndex == str.length-1 ))) {
return false;
}
var reg=/^\w{8,31}$/;
var sup=/[A-Z]{1}?/g;
var low=/[a-z]{1}?/g;
var num=/[0-9][1]?/g;
var arr;
if(str.match(reg)){
arr=str.match(sup);
if(arr && arr.length==1)
{
return (!str.substr(0,1).match(sup) && !str.substr(str.length-1,str.length).match(sup))
}
arr=str.match(low);
if(arr && arr.length==1)
{
return (!str.substr(0,1).match(low) && !str.substr(str.length-1,str.length).match(low))
}
arr=str.match(num);
if(arr && arr.length==1)
{
return (!str.substr(0,1).match(num) && !str.substr(str.length-1,str.length).match(num))
}
for(var i=0;i<str.length/2;i++){
if(str.split(str.substr(0,i+1)).join('')==''){
return false;
}
}
return true;
}
return false;
}
2010-10-26
js判断密码重复规则
<html>
<head>
</head>
<script>
function test(obj){
var str=obj.value;
if(validate(str)){
alert("合法的字符串!");
}else{
alert("非法的字符串!");
}
}
function validate(str){
var reg=/^\w{8,31}$/;
if(str.match(reg)){
for(var i=0;i<str.length/2;i++){
if(str.split(str.substr(0,i+1)).join('')==''){
return false;
}
}
return true;
}
return false;
}
</script>
<body>
输入进行验证:<input type="text" value="" id="text"><br>
<input type="button" value='验证' onclick="test(text)" >
</body>
</html>
2010-10-25
2010.10.22密码校验(小写,大写,数字)
private boolean checkPassword(String password) {
int numberCount = 0;
int upperCaseCount = 0;
int lowerCaseCount = 0;
int numberIndex = 0;
int upperCaseIndex = 0;
int lowerCaseIndex = 0;
for (int i = 0; i < password.length(); i++) {
char temp = password.charAt(i);
if (temp >= 48 && temp <= 57) {
numberIndex = i;
numberCount++;
}else if(temp >= 65 && temp <= 90){
upperCaseIndex = i;
upperCaseCount++;
}else if(temp >= 97 && temp <= 122){
lowerCaseIndex = i;
lowerCaseCount++;
}
}
if (numberCount == 0 || (numberCount == 1 && (numberIndex == 0 || numberIndex == password.length()-1 ))) {
return false;
}
if (upperCaseCount == 0 || (upperCaseCount == 1 && (upperCaseIndex == 0 || upperCaseIndex == password.length()-1 ))) {
return false;
}
if (lowerCaseCount == 0 || (lowerCaseCount == 1 && (lowerCaseIndex == 0 || lowerCaseIndex == password.length()-1 ))) {
return false;
}
return true;
}
2010-10-22
java校验密码重复的代码
public static boolean validatePassword(String str)
{
String REG_PATTERN="^\\w{8,31}$";
Pattern pattern=Pattern.compile(REG_PATTERN);
Matcher matcher=pattern.matcher(str);
if(matcher.matches()){
for(int i=0;i<str.length()/2;i++){
if(str.replaceAll(str.substring(0,i+1), "").length()==0){
return false;
}
}
return true;
}
return false;
}
2010-10-21
java弱口令代码java弱口令代码
public class JJL2 {
public static void main(String[] args) {
System.out.println(new JJL2().checkPassword("123sdhgh*/-/*"));
}
private boolean checkPassword(String password) {
int numberCount = 0;
int letterCount = 0;
int otherCount = 0;
for (int i = 0; i < password.length(); i++) {
char temp = password.charAt(i);
if (temp >= 48 && temp <= 57) {
numberCount++;
}else if((temp >= 65 && temp <= 90) || (temp >= 97 && temp <= 122)){
letterCount++;
}else{
otherCount++;
}
if (numberCount > 0 && letterCount > 0 && otherCount > 0) {
return true;
}
}
return false;
}
}
2010-10-19
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人