简体   繁体   English

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

[英]Regular expression starting with letter only not working

I have the following JSFiddle where I am able to restrict the validation to numbers, characters, no spaces and underscores using this: regexp: /^[A-Za-z0-9_]+$/.我有以下JSFiddle ,我可以在其中使用以下代码将验证限制为数字、字符、无空格和下划线:正则表达式:/^[A-Za-z0-9_]+$/。

However, I want to start it using letter only and not with number or special character or anything else.但是,我只想使用字母而不是数字或特殊字符或其他任何字符来启动它。 I tried this: regexp: /^[a-zA-Z]+[A-Za-z0-9_]+$/, but it doesn't work.我试过这个:正则表达式:/^[a-zA-Z]+[A-Za-z0-9_]+$/,但它不起作用。

What am I doing wrong here?我在这里做错了什么?

 $(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>

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

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

相关问题 从起始字母搜索的Javascript正则表达式? - Javascript regular expression for search from starting letter? JavaScript 中仅大写字母的正则表达式 - Regular expression for upper case letter only in JavaScript Javascript正则表达式中的字母 - Letter in Javascript Regular Expression 正则表达式 - 仅第一个字符检查非字母字符 - Regular Expression - Only first character check non-letter characters 如何验证仅通过 JavaScript 正则表达式输入的字母和空格 - How to validate a letter and whitespace only input via JavaScript regular expression 正则表达式只允许两个下划线,没有其他特殊符号并且前一个或下一个字符应该是数字或字母 - Regular expression to allow only two underscores, absence of other special symbols and previous or next character should number or letter 正则表达式:仅限字母、数字、空格、连字符、句点和下划线,并且必须以字母开头 - Regular Expression: Letters, numbers, spaces, hyphens, periods, and underscores only and must begin with a letter 正则表达式:任何不是字母或数字的字符 - Regular Expression: Any character that is not a letter or number 需要此正则表达式不需要至少1个大写字母 - Need this regular expression not to require at least 1 capital letter 用于检查字母,数字和符号的正则表达式 - Regular Expression to check for letter, number, and symbol
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM