@@ -129,23 +129,145 @@ public String getValue() {
129129 * {@inheritDoc}
130130 */
131131 @ Override
132- public boolean isValid () {
133- if (!super .isValid ()) {
132+ public boolean hasRangeOverflowValidityState () {
133+ if (super .hasRangeOverflowValidityState ()) {
134+ return true ;
135+ }
136+
137+ String rawValue = getRawValue ();
138+ if (org .htmlunit .util .StringUtils .isBlank (rawValue )) {
134139 return false ;
135140 }
136141
142+ if (!hasFeature (JS_INPUT_NUMBER_ACCEPT_ALL )) {
143+ rawValue = rawValue .replaceAll ("\\ s" , "" );
144+ }
145+ if (!rawValue .isEmpty ()) {
146+ if (org .htmlunit .util .StringUtils .equalsChar ('-' , rawValue )
147+ || org .htmlunit .util .StringUtils .equalsChar ('+' , rawValue )) {
148+ return true ;
149+ }
150+
151+ // if we have no step, the value has to be an integer
152+ if (getStep ().isEmpty ()) {
153+ String val = rawValue ;
154+ final int lastPos = val .length () - 1 ;
155+ if (lastPos >= 0 && val .charAt (lastPos ) == '.' ) {
156+ if (hasFeature (JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE )) {
157+ return true ;
158+ }
159+ val = val .substring (0 , lastPos );
160+ }
161+ if (!StringUtils .containsOnly (val , VALID_INT_CHARS )) {
162+ return true ;
163+ }
164+ }
165+
166+ final BigDecimal value ;
167+ try {
168+ value = new BigDecimal (rawValue );
169+ }
170+ catch (final NumberFormatException e ) {
171+ return true ;
172+ }
173+
174+ if (!getMax ().isEmpty ()) {
175+ try {
176+ final BigDecimal max = new BigDecimal (getMax ());
177+ if (value .compareTo (max ) > 0 ) {
178+ return true ;
179+ }
180+ }
181+ catch (final NumberFormatException ignored ) {
182+ // ignore
183+ }
184+ }
185+ }
186+ return false ;
187+ }
188+
189+ /**
190+ * {@inheritDoc}
191+ */
192+ @ Override
193+ public boolean hasRangeUnderflowValidityState () {
194+ if (super .hasRangeUnderflowValidityState ()) {
195+ return true ;
196+ }
197+
137198 String rawValue = getRawValue ();
138199 if (org .htmlunit .util .StringUtils .isBlank (rawValue )) {
200+ return false ;
201+ }
202+
203+ if (!hasFeature (JS_INPUT_NUMBER_ACCEPT_ALL )) {
204+ rawValue = rawValue .replaceAll ("\\ s" , "" );
205+ }
206+ if (!rawValue .isEmpty ()) {
207+ if (org .htmlunit .util .StringUtils .equalsChar ('-' , rawValue )
208+ || org .htmlunit .util .StringUtils .equalsChar ('+' , rawValue )) {
209+ return true ;
210+ }
211+
212+ // if we have no step, the value has to be an integer
213+ if (getStep ().isEmpty ()) {
214+ String val = rawValue ;
215+ final int lastPos = val .length () - 1 ;
216+ if (lastPos >= 0 && val .charAt (lastPos ) == '.' ) {
217+ if (hasFeature (JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE )) {
218+ return true ;
219+ }
220+ val = val .substring (0 , lastPos );
221+ }
222+ if (!StringUtils .containsOnly (val , VALID_INT_CHARS )) {
223+ return true ;
224+ }
225+ }
226+
227+ final BigDecimal value ;
228+ try {
229+ value = new BigDecimal (rawValue );
230+ }
231+ catch (final NumberFormatException e ) {
232+ return true ;
233+ }
234+
235+ if (!getMin ().isEmpty ()) {
236+ try {
237+ final BigDecimal min = new BigDecimal (getMin ());
238+ if (value .compareTo (min ) < 0 ) {
239+ return true ;
240+ }
241+ }
242+ catch (final NumberFormatException ignored ) {
243+ // ignore
244+ }
245+ }
246+ }
247+ return false ;
248+ }
249+
250+ /**
251+ * {@inheritDoc}
252+ */
253+ @ Override
254+ public boolean isStepMismatchValidityState () {
255+ if (super .isStepMismatchValidityState ()) {
139256 return true ;
140257 }
141258
259+ String rawValue = getRawValue ();
260+ if (org .htmlunit .util .StringUtils .isBlank (rawValue )) {
261+ return false ;
262+ }
263+
142264 if (!hasFeature (JS_INPUT_NUMBER_ACCEPT_ALL )) {
143265 rawValue = rawValue .replaceAll ("\\ s" , "" );
144266 }
145267 if (!rawValue .isEmpty ()) {
146268 if (org .htmlunit .util .StringUtils .equalsChar ('-' , rawValue )
147269 || org .htmlunit .util .StringUtils .equalsChar ('+' , rawValue )) {
148- return false ;
270+ return true ;
149271 }
150272
151273 // if we have no step, the value has to be an integer
@@ -154,12 +276,12 @@ public boolean isValid() {
154276 final int lastPos = val .length () - 1 ;
155277 if (lastPos >= 0 && val .charAt (lastPos ) == '.' ) {
156278 if (hasFeature (JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE )) {
157- return false ;
279+ return true ;
158280 }
159281 val = val .substring (0 , lastPos );
160282 }
161283 if (!StringUtils .containsOnly (val , VALID_INT_CHARS )) {
162- return false ;
284+ return true ;
163285 }
164286 }
165287
@@ -168,21 +290,21 @@ public boolean isValid() {
168290 value = new BigDecimal (rawValue );
169291 }
170292 catch (final NumberFormatException e ) {
171- return false ;
293+ return true ;
172294 }
173295
174296 if (!getMin ().isEmpty ()) {
175297 try {
176298 final BigDecimal min = new BigDecimal (getMin ());
177299 if (value .compareTo (min ) < 0 ) {
178- return false ;
300+ return true ;
179301 }
180302
181303 if (!getStep ().isEmpty ()) {
182304 try {
183305 final BigDecimal step = new BigDecimal (getStep ());
184306 if (value .subtract (min ).abs ().remainder (step ).doubleValue () > 0.0 ) {
185- return false ;
307+ return true ;
186308 }
187309 }
188310 catch (final NumberFormatException ignored ) {
@@ -194,18 +316,7 @@ public boolean isValid() {
194316 // ignore
195317 }
196318 }
197- if (!getMax ().isEmpty ()) {
198- try {
199- final BigDecimal max = new BigDecimal (getMax ());
200- if (value .compareTo (max ) > 0 ) {
201- return false ;
202- }
203- }
204- catch (final NumberFormatException ignored ) {
205- // ignore
206- }
207- }
208319 }
209- return true ;
320+ return false ;
210321 }
211322}
0 commit comments