正则表达式的x位数和只有一个连字符?(Regular expression for x number of digits and only one hyphen?)
我做了以下正则表达式:
(\d{5}|\d-\d{4}|\d{2}-\d{3}|\d{3}-\d{2}|\d{4}-\d)
它似乎工作。 也就是说,它会匹配一个5位数字或一个5位数字,只有1个连字符,但连字符不能是前导或末尾。
我想要一个类似的正则表达式,但是对于一个25位数的数字。 如果我使用与上面相同的策略,那么正则表达式将会很长。
任何人都可以建议一个更简单的正则表达式?
附加说明:我将这个正则表达式放入一个将由ASP.NET应用程序使用的XML文件中。 我无法访问.net后端代码。 但我怀疑他们会这样做:
Match match = Regex.Match("Something goes here", "my regex", RegexOptions.None);
I made the following regex:
(\d{5}|\d-\d{4}|\d{2}-\d{3}|\d{3}-\d{2}|\d{4}-\d)
And it seems to work. That is, it will match a 5 digit number or a 5 digit number with only 1 hyphen in it, but the hyphen can not be the lead or the end.
I would like a similar regex, but for a 25 digit number. If I use the same tactic as above, the regex will be very long.
Can anyone suggest a simpler regex?
Additional Notes: I'm putting this regex into an XML file which is to be consumed by an ASP.NET application. I don't have access to the .net backend code. But I suspect they would do something liek this:
Match match = Regex.Match("Something goes here", "my regex", RegexOptions.None);
原文:https://stackoverflow.com/questions/18389043
最满意答案
https://jsfiddle.net/9Luvrvc1/1/
您可以使用相同的代码,在计数器功能处使用减号:
$(document).ready(function() { var count; var interval; $(".ca-top").on('mouseover', function() { var div = $('.navbar-nav.categories'); intervalDown = setInterval(function(){ count = count || 1; var pos = div.scrollTop(); div.scrollTop(pos + count); }, 10); }).click(function() { if (count < 6) { count = count+1; } }).on('mouseout', function() { // Uncomment this line if you want to reset the speed on out count = 0; clearInterval(intervalDown); }); $(".ca-bottom").on('mouseover', function() { var div = $('.navbar-nav.categories'); intervalUp = setInterval(function(){ count = count || 1; var pos = div.scrollTop(); div.scrollTop(pos - count); }, 10); }).click(function() { if (count > 6) { count = count-1; } }).on('mouseout', function() { // Uncomment this line if you want to reset the speed on out count = 0; clearInterval(intervalUp); }); });
但是,您可以尝试创建类似滚动(方向)的功能 - 这将使您的代码更短,更好阅读。
https://jsfiddle.net/9Luvrvc1/1/
You can just use the same code, with a minus at the counter function:
$(document).ready(function() { var count; var interval; $(".ca-top").on('mouseover', function() { var div = $('.navbar-nav.categories'); intervalDown = setInterval(function(){ count = count || 1; var pos = div.scrollTop(); div.scrollTop(pos + count); }, 10); }).click(function() { if (count < 6) { count = count+1; } }).on('mouseout', function() { // Uncomment this line if you want to reset the speed on out count = 0; clearInterval(intervalDown); }); $(".ca-bottom").on('mouseover', function() { var div = $('.navbar-nav.categories'); intervalUp = setInterval(function(){ count = count || 1; var pos = div.scrollTop(); div.scrollTop(pos - count); }, 10); }).click(function() { if (count > 6) { count = count-1; } }).on('mouseout', function() { // Uncomment this line if you want to reset the speed on out count = 0; clearInterval(intervalUp); }); });
However you can try to make a function like scroll(direction) - which will make your code shorter and better to read.
相关问答
更多-
-
那这个呢? $('#spnTop').on("click",function(){ var percentageToScroll = 100; var percentage = percentageToScroll/100; var height = $(document).scrollTop(); var scrollAmount = height * (1 - percentage); alert(scrollAmount); $('html,body' ...
-
如果您不需要更改动画,那么您不需要使用任何特殊的插件 - 我只需使用本机JavaScript window.scrollTo方法 - 传递0,0将立即将页面滚动到左上角。 window.scrollTo(x-coord, y-coord); 参数 x坐标是沿着水平轴的像素。 y坐标是垂直轴上的像素。 If you don't need the change to animate then you don't need to use any special plugins - I'd just use th ...
-
https://jsfiddle.net/9Luvrvc1/1/ 您可以使用相同的代码,在计数器功能处使用减号: $(document).ready(function() { var count; var interval; $(".ca-top").on('mouseover', function() { var div = $('.navbar-nav.categories'); intervalDown = setInterval(funct ...
-
用这个... $(document).ready(function(){ $(".toTop").hide(); $(function () { $(window).scroll(function () { if ($(this).scrollTop() > 200) { $('.toTop').fadeIn(); } else { ...
-
试试这个代码 jQuery(document).ready(function($){ // hide the topbutton on page load/ready. $('.TopButton').hide(); //Check to see if the window is top if not then display button $(window).scroll(function(){ if ($(this).scrollTop() > 100 ...
-
jQuery:自动滚动到顶部(jQuery: Auto scroll to top)[2024-01-16]
您可以将position: fixed ,例如top: 30px到#popup_bestanden_edit_name样式中。 如果你这样做,无论用户在页面上的哪个位置,模态都会出现在同一个地方。 但是你必须小心,因为如果模态高于视口,你将无法看到模态的剩余部分。 如果你仍然想滚动到顶部(没有动画),可以使用JavaScript $('body').scrollTop(0); 在你return false;之前就是return false; 顺便说一句,如果你想阻止链接的默认动作触发,最好这样做: $(' ... -
$(window).off("scroll"); 确实正在删除你正在收听fadeIn和fadeOut的scroll事件。 虽然我没有尝试过,但另一种方法是使用事件命名空间 ? 如下所示: $.chain = function() { var promise = $.Deferred().resolve().promise(); jQuery.each( arguments, function() { promise = promise.pipe( this ); }); ...
-
滚动到顶部/底部按钮错误(Scroll to top/bottom button error)[2022-07-06]
关闭DIV标签时出错。 试试这个HTML标记: 事实上,你的第一个DIV(up)并不算是封闭的,所以你的第二个div是“内部”向上按钮,所以两个事件被捕获下来。 小提琴 You make a mistake on closing ... -
滚动到热门jQuery(Scroll to Top jQuery)[2022-03-12]
好吧,你告诉它每次触发滚动事件时附加,所以先检查它是否存在,看看它是否适合你。 $(window).scroll(function () { var scrollPosition = $(this).scrollTop(); var toTops = $('.back-to-top'); // get jQ object once if (scrollPosition >= 500) { if (!toTops.length){ // if no elems ...