Java 实现校验手机号格式方法

java:实现判断手机号码的合法性(附完整源码) 阅读详情

可以使用正则表达式来校验手机号格式。以下是一个示例方法:

public static boolean isValidPhoneNumber(String phoneNumber) {
    String regex = "^1[3-9]\\d{9}$";
    return phoneNumber.matches(regex);
}

其中,正则表达式^1[3-9]\\d{9}$表示:

  • ^ 表示字符串的开头
  • 1 表示第一位必须为数字 1
  • [3-9] 表示第二位为数字 3 到 9 中的任意一个
  • \\d{9} 表示后面必须跟着 9 位数字
  • $ 表示字符串的结尾

因此,这个方法会校验输入的字符串是否符合中国手机号码格式,如果符合返回 true,否则返回 false。

Java-手机号码检验 移动:134、135、136、137、138、139、150、151、152、157、158、159、172、178、182、正则表达式来判断该字符串是否符合中国大陆手机号码的格式。在Java中,检验手机号码的有效性通常通过正则表达式来实现。联通:130、131、132、155、156、171、175、176、185、186。电信:133、153、173、174、180、181、189、199。[3-9] 匹配第二位数字,可以是从3到9中的任意一个数字。1 匹配手机号的第一位数字,必须是1。 阅读详情

相关推荐

java 使用正则表达式验证电话号码的格式

java 使用正则表达式验证电话号码的格式 java 使用正则表达式验证电话号码的格式

Java:验证手机号

idea使用Java通过输入的手机号,判断是否正确

qq_45138120的博客 6884

视觉语言模型对抗攻击与防御:从传统方法到多模态挑战

本文深入探讨了视觉语言模型(VLM)面临的对抗攻击与防御挑战,从传统单模态攻击到多模态威胁的演进。分析了包括FGSM、PGD等经典攻击方法,以及新兴的多模态攻击如跨模态对抗样本和越狱攻击。同时提出了跨模态一致性检查、动态防御机制等创新防御策略,并结合医疗影像诊断等实战案例,为提升AI系统安全性提供了重要见解。

weixin_29231725的博客 393

java正则表达式(附带案例——检测手机号码是否合法)

Java正则表达式是一种用于匹配字符串的模式,它可以用来检查一个字符串是否符合某种格式,或者从一个字符串中提取出符合某种格式的子串。3. 排除类:用脱字符^表示,匹配除了脱字符后面的字符以外的任意一个字符。例如,[^abc]匹配除了a、b、c以外的任意一个字符。例如,a{3}匹配aaa,a{1,3}匹配a、aa或aaa。9. 边界匹配:用^表示字符串的开头,用$表示字符串的结尾。2. 范围类:用连字符-表示,匹配连字符两端的任意一个字符。1. 字符类:用方括号[]表示,匹配方括号中的任意一个字符。

weixin_51546708的博客 5385

拆开一个烧坏的IGBT模块,手把手教你识别过压、过流、过温的“案发现场”

本文详细解析了IGBT模块失效分析的实战技巧,通过观察铝层熔化纹路、焊锡溢出形态等物理痕迹,手把手教你识别过压、过流、过温的典型失效模式。文章提供了从基础工具包到现场快速诊断的完整流程,帮助工程师精准定位IGBT模块失效的根本原因。

weixin_30655569的博客 427

【云迁移工具RDA】迁移常见问题

Agent无法正常启动,Linux系统提示“SMS.0201 Failed to start sms agent!”,Windows系统提示“SMS.0201 源端主机网络繁忙,无法连接api网关”。该问题通常是由于源端没有通公网,或者没有按照要求配置hosts,无法与iam或者sms通信导致。需要排查源端网络。1.登录源端服务器。2.检查源端是否能正常访问互联网,若无法访问,请处理后重新启动Agent。可参考弹性公网IP Ping不通检查源端的DNS,防火墙,安全组、本地网络等。

2404_89358774的博客 1487

Java校验手机号格式

package com.shucha.digitalportalbackstage.biz.utils; import org.springframework.stereotype.Component; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author tqf * @Description 手机号格式校验 * @Version 1.0 * @since 2022-03-15 15:28 .

tanqingfu1的博客 1965

六维力传感器选型指南:电阻式vs电容式,哪个更适合你的工业场景?

本文深入解析六维力传感器在工业自动化中的选型要点,重点对比电阻式与电容式传感器的核心原理、环境适应性及成本结构。针对不同工业场景(如高精度装配、重载机器人等),提供专业选型建议,帮助工程师优化系统性能与经济效益。

weixin_42525005的博客 397

Java 正则校验手机号 工具类

List: 1.需求 2.代码 3.总结 ……1.需求……               前后台分离开发,就需要对传参的数据进行校验,你不知道前端会给你传过来什么乱七八糟的数据,如果在后面的逻辑里面出错了。那就是你后端的问题了。所以传参接收来的数据校验十分重要。我负责的模块很多地方都需要传用户手机号,然后给手机号发送验证码,或者调用第三方征信平台来获取凭证。所以,手机号的真实性尤

周洲 (Julie) 7232

python实现下载和离线安装包环境

导出当前电脑python安装的所有包列表requirement.txt。

m0_60352504的博客 1677

通过Simulink搭建一个智能微电网能量管理系统(Energy Management System, EMS)

通过上述代码实现,您可以逐步创建一个智能微电网能量管理系统。多源能量集成:整合光伏、风力发电、柴油发电机、电池储能等多种能源资源。负荷预测与调度:基于历史数据和天气预报,预测未来负荷和可再生能源输出,进行优化调度。储能系统优化:设计合理的充放电策略,确保储能系统的高效利用和寿命延长。经济性分析:评估不同运行模式下的经济性,考虑电价、维护成本等因素。环境影响评估:分析微电网对环境的影响,如减少碳排放、提高可再生能源利用率等。硬件在环仿真(HILS)

amy_mhd的博客 314

Java 使用注解检验手机号

手机号校验注解类package com.command.util;import static java.lang.annotation.ElementType.CONSTRUCTOR; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD;

_binlong的博客 2万+

AI自瞄原理剖析(四)从Yolo推理坐标到屏幕坐标:基于FOV视角与焦距的坐标变换与精准瞄准

从Yolo推理框架得到的坐标到屏幕坐标的转换是一个涉及到FOV视角、焦距以及分辨率的复杂过程。通过数学公式,我们可以将推理框坐标反推为游戏内的实际坐标,并最终映射到屏幕坐标系中。利用这些信息,AI自瞄系统能够精确计算出准星从当前位置移动到敌人位置的距离,实现精准的自动瞄准。通过这种方法,AI自瞄系统能够在不同的游戏环境下灵活应对,提供高度精确的操作体验。在AI自瞄系统中,目标检测仅仅是第一步,获取到预测框的坐标后,我们还需要将这些坐标转换为实际屏幕上的精确位置。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1334

通过实现ConstraintValidator完成自定义校验注解

首先贴上代码 @Data public class LoginVO { @NotNull @IsMobile private String mobile; @NotNull @Length(min = 32) private String password; } public class IsMobileValidator implements...

java牛牛的博客 1218

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【Java工具类】基于正则的手机号、密码、邮箱格式检测

Java工具类 基于正则的手机号、密码格式检测

zxy2361380031的博客 849

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

java身份证号码正则表达式校验(亲测可用) Java正则校验手机号

// 原文:https://blog.youkuaiyun.com/u011106915/article/details/76066985 public class IDUtils { public static boolean isIDNumber(String IDNumber) { if (IDNumber == null || "".equals(IDNumber)) { return false; } // 定义判别用户身份证号的...

易的博客 1万+

java 格式化手机号码_java邮箱校验,手机号校验,格式化日期等等

import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.regex.Matcher;import java.util.regex.Pattern;import 这个是传入数据的封装jar包,可以不用看,具体看自己需求context.Recordset;public class ApplyUtil {p...

weixin_31759829的博客 344

ConstraintValidator 实现自定义注解

在工作中有时需要实现校验,错误信息自定义,这时自定义注解就起作用了 1、首先需要创建一个注解类: @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Documented @Constraint( validatedBy = {IsMobileValidator.class} ) public @int...

wangc_gogo的博客 4888

java电话号码_java 验证手机号码、电话号码(包括最新的电信、联通和移动号码)...

package com.linbilin.test;import java.util.regex.Pattern;public class CheckPhone {/** 座机电话格式验证 **/private static final String PHONE_CALL_PATTERN = "^(?:\\(\\d{3,4}\\)|\\d{3,4}-)?\\d{7,8}(?:-\\d{1,4})?...

weixin_42517044的博客 404

java --手机号码校验

/** * 手机号码校验 * @param number * @return */ public static boolean checkMobilePhone(String number) { boolean result = false; try { String regex = "[0-9]{11}$"; Pattern check = Pattern.compile...

weixin_33994444的博客 312

各种常用格式校验方法(身份证号格式校验、手机号格式校验、车牌号格式校验...)正则表达式

7、校验字符串是否符合年月日yyyyMMdd时间格式。6、校验字符串是否符合年月yyyyMM时间格式。2、手机号格式校验(2)包含座机及外国电话。4、车牌号格式校验,包含新能源。1、手机号格式校验(1)3、身份证号格式校验。

Colin的博客 861

java正则表达式判断手机号、邮件、QQ格式校验

具体理解推荐 package test; public class Expression { public static void main(String[] args) { System.out.println("手机号" + isPhone("18768668681")); System.out.println("随意" + isPhone("11168668681")); System.out.println("qq.com" + "\t" + isEmail("318717611@qq

qq_54660143的博客 1636

利用hibernate-validator-5.3 实现校验

1.定义注解IsMobile @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy={IsMobileValidator.class}) public @interface IsMobile { boolean required() default true; Strin...

三五二十五的博客 783
上一篇: Java简单实现邮箱登录功能
下一篇: 使用java实现将手机号码储存在二维码上,扫码二维码即可拨打电话
懒人刘
博客等级 码龄4年 541粉丝 263原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值