繁体   English   中英

仅以字母开头的正则表达式不起作用

[英]Regular expression starting with letter only not working

我有以下JSFiddle ,我可以在其中使用以下代码将验证限制为数字、字符、无空格和下划线:正则表达式:/^[A-Za-z0-9_]+$/。

但是,我只想使用字母而不是数字或特殊字符或其他任何字符来启动它。 我试过这个:正则表达式:/^[a-zA-Z]+[A-Za-z0-9_]+$/,但它不起作用。

我在这里做错了什么?

 $(document).ready(function() { function getConcepts() { var bootstrapValidator = $("#validateForm").data('bootstrapValidator'); bootstrapValidator.validate(); if (bootstrapValidator.isValid()) { $("#validateForm").submit(); console.log("Submitting form after validation"); } else { console.log("Bootstrap fields are not validated"); return; } } $("#conceptsButton").click(getConcepts); //BEGIN FORM Validations $('#validateForm').bootstrapValidator({ feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { titleOfResearchProject: { validators: { stringLength: { min: 4, max: 10, message: 'Please Enter the title with minimum 4 & max 10 characters' }, notEmpty: { message: 'Please Enter title of your project' }, regexp: { //regexp: /^[\w]+$/, //regexp: /^[A-Za-z0-9_]+$/, regexp: /^[a-zA-Z]+[A-Za-z0-9_]+$/, message: 'You can introduce just alphabetical characters, underscore, number but no spaces' } } }, } }); //END FORM Validations });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <:-- BEGIN Bootstrap form testing--> <form class="form-horizontal" id="validateForm"> <div class="row"> <div class="col-md-offset-1 col-md-4"> <div class="form-group"> </div> <div class="form-group"> </div> </div> <div class="col-md-offset-1 col-md-4"> <div class="form-group"> <label class="control-label">Title of your research project.</label> <input name="titleOfResearchProject" placeholder="Enter your title here...:" class="form-control" type="text"> </div> <div class="form-group"> </div> </div> </div> <button class="btn btn-success" id="conceptsButton">Request Data</button> </form> <div id="add_dialog" title="Add New Data" style="display;none;"> </div>

您可以使用正则表达式: ^[a-zA-Z].*\w+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM