我需要帮助创建一个4,000-1,000,000的数字范围的正则表达式,逗号和美元符号对用户是可选的。
我正在尝试使用带有正则表达式的自定义表达式或自定义验证程序来批准部门预算的验证,该验证程序允许使用可选的美元符号和逗号,范围从$ 5000.00到$ 1,000,000
^\$?([5-9][0-9]{3,5}|1000000)$
可悲的是,这不起作用,这是我提出的,任何帮助将不胜感激!
答案 0 :(得分:2)
^\$?(?:[5-9],?\d{3}|[1-9]\d{1,2},?\d{3}|1,000,000|1000000)$
答案 1 :(得分:1)
修改 添加可选的美元符号\$?
^(?:[5-9],?\d{3}|[1-9]\d{1,2},?\d{3}|1,000,000|1000000)$
扩展
^
(?:
[5-9] ,? \d{3}
| [1-9] \d{1,2} ,? \d{3}
| 1, 000 , 000
| 1 000 000
)
$
答案 2 :(得分:1)
绝对是一个可靠的选择,但是如果你注意到结局,你可以采用一种更简单的方式,即下面的第二种方式,?使它的长度变短。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.venon.nakomangsp, PID: 20610
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=132074, result=-1, data=Intent { dat=content://media/external/images/media/4147 (has extras) }} to activity {com.venon.nakomangsp/com.venon.nakomangsp.SignUpActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4058)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4101)
at android.app.ActivityThread.access$1400(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1497)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at id.zelory.compressor.ImageUtil.getScaledBitmap(ImageUtil.java:62)
at id.zelory.compressor.ImageUtil.compressImage(ImageUtil.java:161)
at id.zelory.compressor.Compressor.compressToFile(Compressor.java:48)
at com.venon.nakomangsp.SignUpFragment.preparePicture(SignUpFragment.java:870)
at com.venon.nakomangsp.SignUpFragment.onActivityResult(SignUpFragment.java:783)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:165)
at com.venon.nakomangsp.SignUpActivity.onActivityResult(SignUpActivity.java:37)
at android.app.Activity.dispatchActivityResult(Activity.java:6549)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4054)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4101)
at android.app.ActivityThread.access$1400(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1497)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
VS
^(?:5,?\d{3}|[6-9],?\d{3}|[1-9]\d{1,2},?\d{3}|1,000,000|1000000)$
第二个是更清洁,从我能说的全部工作。