我正在尝试验证我的电话地址文字字段。任何人都可以为我提供一个简单的正则表达式来验证只有数字或特定的8位正则表达式吗?
非常感谢!
$('#phone').on('input', function() {
var input = $( this );
var regex = /* regex needed here */
var is_phone = regex.test(input.val());
if (is_phone){input.removeClass("invalid").addClass("valid");}
else {input.removeClass("valid").addClass("invalid");}
});
答案 0 :(得分:3)
它将允许0-9个数字,只有8个数字。试试这个:
package com.androidexample.screenonoff;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class AEScreenOnOffService extends Service {
BroadcastReceiver mReceiver=null;
@Override
public void onCreate() {
super.onCreate();
// Toast.makeText(getBaseContext(), "Service on create", Toast.LENGTH_SHORT).show();
// Register receiver that handles screen on and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new AEScreenOnOffReceiver();
registerReceiver(mReceiver, filter);
}
@Override
public void onStart(Intent intent, int startId) {
boolean screenOn = false;
try{
// Get ON/OFF values sent from receiver ( AEScreenOnOffReceiver.java )
screenOn = intent.getBooleanExtra("screen_state", false);
}catch(Exception e){}
// Toast.makeText(getBaseContext(), "Service on start :"+screenOn,
//Toast.LENGTH_SHORT).show();
if (!screenOn) {
// your code here
// Some time required to start any service
//Toast.makeText(getBaseContext(), "Begin ", Toast.LENGTH_LONG).show();
// Intent yourintent = new Intent(this, postlockscreen.class);
//yourintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//startActivity(yourintent);
} else {
// your code here
// Some time required to stop any service to save battery consumption
//Toast.makeText(getBaseContext(), "Screen off,", Toast.LENGTH_LONG).show();
Intent yourintent = new Intent(this, postlockscreen.class);
yourintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(yourintent);
}
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}